3

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

2
  • is DingButton::DingButton(QWidget*) implemented ? Commented Apr 15, 2014 at 9:31
  • @KeillRandor Yes, DingButton::DingButton(QWidget* ) is implemented Commented Apr 15, 2014 at 12:36

1 Answer 1

1

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
{

}
Sign up to request clarification or add additional context in comments.

2 Comments

It should be DingButton::DingButton(QWidget *widget) : QWidget(widget) to inherit correcly the parent.
oops forgot this part, you are right of course. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.