Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I use my own subclass in the ui?

How do I use my own subclass in the ui?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 726 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lansing
    wrote on last edited by
    #1

    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.

    my_spinbox.h

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

    my_spinbox.cpp

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

    What is wrong?

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

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

      HEADERS += my_spinbox.h
      SOURCES += my_spinbox.cpp
      
      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        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.

        L 1 Reply Last reply
        4
        • mrjjM mrjj

          Hi
          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.

          L Offline
          L Offline
          lansing
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved