Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt custom widget error

Tags:

c++

qt

I'm trying to make simple custom widget in Qt(named DingButton, inherited from QPushButton). I made it. It is seen in Qt Designer. But when I compile project(named DingDemo) which includes this custom widget I get an error:

undefined reference to `DingButton::DingButton(QWidget*)

which points to the next code in 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

I've searched the Internet and tried to follow next instruction:

  • add the line:

    LIBS += -Wl,-rpath,/usr/local/qt4/plugins/designer -L/usr/local/qt4/plugins/designer -l libding-button-plugin.so

to .pro file

  • create .pri file and include it to .pro

But that wasn't successful.

Why this happens? And how to get through this?

Please, help me

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

EDIT: DingButton::DingButton(QWidget* ) is implemented

like image 896
Andrii Lisun Avatar asked Dec 19 '25 22:12

Andrii Lisun


1 Answers

You have to implement this constructor which is being called in the line where the error occurs.

DingButton(QWidget *widget = 0);//In your DingButton class

DingButton::DingButton(QWidget *widget) : QWidget(widget) //In your .cpp
{

}
like image 52
Stephan Avatar answered Dec 21 '25 11:12

Stephan