我想创建自己的自定义窗口小部件来扩展QFrame,但是当我尝试使构造函数出现错误时。
#ifndef CONTROLFRAME_H
#define CONTROLFRAME_H
#include <QObject>
#include <QFrame>
#include <QWidget>
#include <QtGui>
class ControlFrame : public QFrame
{
Q_OBJECT
public:
ControlFrame(QWidget *parent = 0);
~ControlFrame();
private:
QWidget *m_parent;
};
#endif // CONTROLFRAME_H
和CPP
#include "controlframe.h"
ControlFrame::ControlFrame(QWidget *parent)
: QFrame(parent)
{
m_parent = parent;
}
ControlFrame::~ControlFrame()
{
}
可悲的是,我收到以下错误
Undefined symbols for architecture x86_64:
"vtable for ControlFrame", referenced from:
ControlFrame::ControlFrame(QWidget*) in controlframe.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [PFEtest.app/Contents/MacOS/PFEtest] Error 1
18:54:21: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project PFEtest (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"
我究竟做错了什么?
最佳答案
我认为,如果您从.h中删除Q_OBJECT
,那就没问题了。我不确定,但是因为您是从QFrame继承的,所以对象中已经有了Q_OBJECT
。