1
我正在創建一個將DoubleClickEvent添加到其中的QLabel子類。我創建了以下內容,但我遇到了一些奇怪的鏈接器錯誤,也許有人可以指出我做錯了什麼?使用doubleclick事件創建QLabel時的鏈接器錯誤
//Header
#ifndef IMAGE_LABEL_H
#define IMAGE_LABEL_H
#include <QLabel>
#include <QMouseEvent>
class image_label : public QLabel
{
Q_OBJECT
public:
image_label(QWidget* parent = 0);
~image_label();
signals:
void doubleClicked();
protected:
void mouseDoubleClickEvent(QMouseEvent * e);
};
#endif
//CPP
#include "image_label.h"
#include <QMouseEvent>
image_label::image_label(QWidget* parent) : QLabel(parent)
{
}
image_label::~image_label()
{
}
void image_label::mouseDoubleClickEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
emit doubleClicked();
QLabel::mouseDoubleClickEvent(e);
}
}
我得到下面的連接錯誤,當我編譯:
image_label.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall image_label::metaObject(void)const " ([email protected][email protected]@[email protected]@XZ)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall image_label::qt_metacast(char const *)" ([email protected][email protected]@[email protected])
image_label.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall image_label::qt_metacall(enum QMetaObject::Call,int,void * *)" ([email protected][email protected]@[email protected]@@[email protected])
image_label.obj : error LNK2019: unresolved external symbol "protected: void __thiscall image_label::doubleClicked(void)" ([email protected][email protected]@IAEXXZ) referenced in function "protected: virtual void __thiscall image_label::mouseDoubleClickEvent(class QMouseEvent *)" ([email protected][email protected]@[email protected]@@Z)
任何人可以幫助我爲什麼得到這些錯誤?
不在QT中,但看到過這樣的鏈接錯誤[之前](http://stackoverflow.com/questions/10006711/eclipse- c-project-not-building-constructor-destructor-issue/10007510#10007510)。你沒有定義任何虛函數。最有可能的,不只是值得檢查,我認爲。 – 2012-04-04 10:54:12