簡體   English   中英

初始化類-未解析的外部符號

[英]Initializing a Class - Unresolved External Symbol

我在初始化類時遇到了麻煩,而我的搜索發現的所有結果都是其他各種問題。

我正在嘗試使用InkSpot *ink;初始化該類InkSpot *ink; 在頭文件中,然后當類需要初始化時,我用ink = new InkSpot(this); <-此行導致錯誤。

inkpuppet.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl InkSpot::InkSpot(class QWidget *)" (??0InkSpot@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl InkPuppet::testButton(void)" (?testButton@InkPuppet@@AEAAXXZ)

我是C ++的新手,無法解決類。 這是我的代碼。

inkpuppet.cpp

#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include "newdialog.h"
#include "inkspot.h"

#include <Qt>
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
#include <QDialog>
#include <QMainWindow>


InkPuppet::InkPuppet(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::InkPuppet)
{
    ui->setupUi(this);

    //connect the frame range boxes to the timeslider
    connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMinimum(int)));
    connect(ui->upperFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMaximum(int)));

    //connect the menu items
    connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(actionNew()));

    //connect test
    connect(ui->testButton, SIGNAL(clicked()), this, SLOT(testButton()));


}

InkPuppet::~InkPuppet()
{
    delete ui;
}

void InkPuppet::setMinimum(int value)
{
    ui->timeSlider->setMinimum(value);
}

void InkPuppet::setMaximum(int value)
{
    ui->timeSlider->setMaximum(value);
}

void InkPuppet::actionNew()
{
    NewDialog *dialog = new NewDialog;
    dialog->setModal(true);
    dialog->show();
}

void InkPuppet::testButton()
{
    ink = new InkSpot(this);
    ui->testButton->setText("working");
    //ui->paintAreaLayout->addWidget(ink->widget);
    //QWidget *widg = new QWidget();
    ui->paintAreaLayout->addWidget(ink->widget);

}

inkpuppet.h

#ifndef INKPUPPET_H
#define INKPUPPET_H

#include "inkspot.h"
#include "ink.h"

#include <QMainWindow>
#include <QWidget>

namespace Ui {
class InkPuppet;
}

class InkPuppet : public QMainWindow
{
    Q_OBJECT

public:
    explicit InkPuppet(QWidget *parent = 0);
    ~InkPuppet();
    InkSpot *ink;

private slots:
    void setMinimum(int value);
    void setMaximum(int value);
    void actionNew();
    void testButton();

public:
    Ui::InkPuppet *ui;
};

#endif // INKPUPPET_H

inkspot.cpp

#include "inkspot.h"
#include "inkpuppet.h"
#include "ui_inkpuppet.h"

#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>


void InkSpot::paintEvent(QPaintEvent *event)
{
    QFile *brushInput; //takes raw 8 bit grayscale image, 8 bit values only
    char *brushProto;
    uchar *brushData;

    brushInput = new QFile("x:\\Development\\InkPuppet\\brush.raw"); //open the raw file
    brushInput->open(QIODevice::ReadOnly);
    QDataStream in;
    in.setDevice(brushInput);
    int size = brushInput->size(); //set size to length of raw file

    brushProto = new char[size];
    in.readRawData(brushProto, size); //read file into prototype
    brushData = new uchar[size];

    for(int i = 0; i < size; ++i)
    {
        brushData[i] = (uchar)brushProto[i]; //copy char to uchar array
    }

    QImage test(brushData, 128, 128, QImage::Format_Indexed8);
    QImage test2(128, 128, QImage::Format_ARGB32);

    QVector<QRgb> vectorColors(256); //create color table
    for(int c = 0; c < 256; c++)
    {
        vectorColors[c] = qRgb(c, c, c);
    }

    test.setColorTable(vectorColors);

    for(int iX = 0; iX < 100; ++iX)
    {
        for(int iY = 0; iY < 100; ++iY)
        {
            test2.setPixel(iX, iY, qRgba(255 - (qrand() % 100), 0 + (qrand() % 100), 0 + (qrand() % 100), qAbs((int)test.pixel(iX, iY)-255)));
        }
    }

    //final conversion for stencil and color brush
    QPixmap testPixmap = QPixmap::fromImage(test2);
    QPixmap testPixmap2 = QPixmap::fromImage(test);

    QPainter painter(this);

    painter.drawPixmap(150, 50, 100, 100, testPixmap);
    painter.drawPixmap(50, 50, 100, 100, testPixmap2);

    delete[] brushProto;
    delete[] brushData;
    delete brushInput;
}

墨水點

#ifndef INKSPOT_H
#define INKSPOT_H

#include <QObject>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QLabel>

namespace Ui {
class InkSpot;
}

class InkSpot : public QWidget
{
    Q_OBJECT
public:
    explicit InkSpot(QWidget *parent = 0);
    ~InkSpot();
    void draw(QPainter *painter);
    QWidget *widget;
    QLabel *label;
signals:

public slots:

protected:
    void paintEvent(QPaintEvent *event);

private:
    Ui::InkSpot *ui;

};

#endif // INKSPOT_H

我正在查看您發布的有關InkSpot::InkSpot(QWidget *parent)定義的所有代碼,但沒有看到。 錯誤消息告訴您尚未定義。 所以我認為那一定是問題所在。

僅僅在頭文件中放置某些內容的聲明是不夠的,您還必須在其中定義它。 您使用InkPuppet::InkPuppet(QWidget *parent) ,因此您只需要使用InkSpot::InkSpot(QWidget *parent)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM