我正在尝试在Qt中创建简单的自定义小部件(名为DingButton,继承自QPushButton)。 我做到了。在Qt Designer中可以看到它。但是当我编译包含这个自定义小部件的项目(名为DingDemo)时,我收到一个错误:
未定义引用`DingButton :: DingButton(QWidget *)
指向ui_DingDemo.h中的下一个代码:
class Ui_DingDemo
{
public:
DingButton *dingbutton;
void setupUi(QWidget *DingDemo)
{
if (DingDemo->objectName().isEmpty())
DingDemo->setObjectName(QString::fromUtf8("DingDemo"));
DingDemo->resize(226, 97);
dingbutton = new DingButton(DingDemo); //<---------error here
我搜索了互联网,并尝试按照下一条说明进行操作:
添加以下行:
LIBS + = -Wl,-rpath,/ usr / local / qt4 / plugins / designer -L / usr / local / qt4 / plugins / designer -l libding-button-plugin.so
到.pro文件
但那并不成功。
为什么会这样?以及如何解决这个问题?
请帮帮我
ding-button-plugin.pro
CONFIG += plugin release designer
TEMPLATE = lib
TARGET = $$qtLibraryTarget($$TARGET)
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
INCLUDEPATH += .
LIBS += -Wl,-rpath,/usr/local/qt4/plugins/designer -L/usr/local/qt4/plugins/designer -l libding-button-plugin.so
HEADERS += DingButton.h DingButtonPlugin.h
SOURCES += DingButton.cpp DingButtonPlugin.cpp
编辑: DingButton :: DingButton(QWidget *)已实现
答案 0 :(得分:0)
您必须实现在发生错误的行中调用的构造函数。
DingButton(QWidget *widget = 0);//In your DingButton class
DingButton::DingButton(QWidget *widget) : QWidget(widget) //In your .cpp
{
}