我想创建自己的自定义小部件来扩展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"
我做错了什么?
答案 0 :(得分:-2)
我想如果你从你的.h中移除Q_OBJECT
就可以了。我不确定,但是因为你从QFrame继承,你的对象中已经有Q_OBJECT
。