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. [Solved]Subclass QTabWidget
Forum Updated to NodeBB v4.3 + New Features

[Solved]Subclass QTabWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.0k 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.
  • T Offline
    T Offline
    TFabbri
    wrote on last edited by
    #1

    Hi to all,
    I want to subclass qTabWidget for accessing to qTabbar member for adding some tab with a push button.
    I've followed this old "discussion":http://qt-project.org/forums/viewthread/9548.
    Now, I want to define a slot in my custom widget for removing the tab with close button.
    The subclass is now the following:

    @class TabWidget : public QTabWidget {
    Q_OBJECT
    public:
    TabWidget();
    TabWidget(QWidget *parent);
    ~TabWidget();
    QTabBar *tabBar() const;
    public slots:
    void deleteTab(int index);
    };
    @

    But during the compile process I obtain this errors:

    @
    ..C2/TabWidget.cpp:10: undefined reference to vtable for TabWidget' ..C2/TabWidget.cpp:10: undefined reference to vtable for TabWidget'
    ..C2/TabWidget.cpp:12: undefined reference to vtable for TabWidget' ..C2/TabWidget.cpp:12: undefined reference to vtable for TabWidget'
    @

    Where's the problem? I've used two separate files (.cpp + .h) and I've executed qmake.
    Thank you so much

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      From the output: "TabWidget.cpp".... lines 10 and 12 to be more specific.

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TFabbri
        wrote on last edited by
        #3

        @TabWidget::TabWidget(){} // line 10

        TabWidget::TabWidget(QWidget * p=0) : QTabWidget(p) {} // line 12

        TabWidget::~TabWidget(){} // line 14

        QTabBar * TabWidget::tabBar() const {return QTabWidget::tabBar();}@

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Code_ReaQtor
          wrote on last edited by
          #4

          I see what is wrong with the code:

          line 12 contains QWidget * p = 0 which is not correct. "Default parameters" should be done on the header file:

          @//.h
          class TabWidget : public QTabWidget {
          Q_OBJECT
          public:
          TabWidget();
          TabWidget(QWidget *parent = 0); // Default parameter should be placed here
          ~TabWidget();
          QTabBar *tabBar() const;
          public slots:
          void deleteTab(int index);
          };
          @

          @//.cpp
          TabWidget::TabWidget(){} // line 10

          TabWidget::TabWidget(QWidget * p) : QTabWidget(p) {} // changed line 12

          TabWidget::~TabWidget(){} // line 14

          QTabBar * TabWidget::tabBar() const {return QTabWidget::tabBar();}@

          And I also found something odd... You have "multiple default constructors"

          @TabWidget(); //default constructor, cause of error in line 10.
          TabWidget(QWidget *parent = 0); //another default constructor@

          A word of advice, some compiler might throw warnings, some might throw errors. It is better to remove these lines:
          @TabWidget(); ///found in the header

          TabWidget::TabWidget(){} //line 10, found in the .cpp file@

          Please visit my open-source projects at https://github.com/Code-ReaQtor.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            That error usually is caused by moc not doing its thing and that by qmake not having noticed that this file needs to be moc'ed.

            So rerun qmake and try again.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TFabbri
              wrote on last edited by
              #6

              Now it works.
              I don't know why before qmake doesn't work.
              Thank you so much!

              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