我正在创建一个 QLabel 子类,它将 DoubleClickEvent 添加到它。我已经创建了以下内容,但是我遇到了一些奇怪的链接器错误,也许有人可以指出我做错了什么?
//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 " (?metaObject@image_label@@UBEPBUQMetaObject@@XZ)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall image_label::qt_metacast(char const *)" (?qt_metacast@image_label@@UAEPAXPBD@Z)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall image_label::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@image_label@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
image_label.obj : error LNK2019: unresolved external symbol "protected: void __thiscall image_label::doubleClicked(void)" (?doubleClicked@image_label@@IAEXXZ) referenced in function "protected: virtual void __thiscall image_label::mouseDoubleClickEvent(class QMouseEvent *)" (?mouseDoubleClickEvent@image_label@@MAEXPAVQMouseEvent@@@Z)
谁能帮助我为什么会收到这些错误?