Qt World Summit: Submit your Presentation

How do I use my own subclass in the ui?

  • I have extended the QDoubleSpinBox to my own subclass MySpinBox, then I created a doublespinbox object in the ui designer and promoted it to use MySpinBox class. But when I ran it, it gave me this long error:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl MySpinBox::MySpinBox(class QWidget *)" (??0MySpinBox@@QEAA@PEAVQWidget@@@Z) referenced in function "public: void __cdecl Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QEAAXPEAVQMainWindow@@@Z)

    This is my files.


    #ifndef MY_SPINBOX_H
    #define MY_SPINBOX_H
    #include <QDoubleSpinBox>
    class MySpinBox: public QDoubleSpinBox
        MySpinBox(QWidget *parent = nullptr);
    #endif // MY_SPINBOX_H


    #include "my_spinbox.h"
    MySpinBox::MySpinBox(QWidget *parent): QDoubleSpinBox(parent)

    What is wrong?

  • Hi, in your .pro file, check if you have

    HEADERS += my_spinbox.h
    SOURCES += my_spinbox.cpp

  • Lifetime Qt Champion

    Also sometimes it can be a bit happy to cache files
    so if you have headers as @hskoglund says then
    go and delete your build folder and run qmake and rebuild all.

  • @mrjj Thank you, that's the problem. I deleted the build folder and rebuild it again and it works.

Log in to reply