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. Subclassing QTreeWidgetItem
Forum Update on Monday, May 27th 2025

Subclassing QTreeWidgetItem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.1k Views
  • 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.
  • K Offline
    K Offline
    kouros
    wrote on last edited by
    #1

    Hello can anyoune explain me how to subclass QTreeWidgetIem? Please help me.

    Here is the compiler error.
    @
    /home/serge/Desktop/build-openhomedesigner-Desktop-Debug/moc_treewidgetitem.cpp:52: error: 'staticMetaObject' is not a member of 'QTreeWidgetItem'
    { &QTreeWidgetItem::staticMetaObject, qt_meta_stringdata_TreeWidgetItem,
    ^
    @

    Here is my header and my source file.
    @
    #ifndef TREEWIDGETITEM_H
    #define TREEWIDGETITEM_H

    #include <QtCore>
    #include <QtGui>

    class TreeWidgetItem : public QTreeWidgetItem{
    Q_OBJECT

    public:
    explicit TreeWidgetItem(QTreeWidget *parent = 0, int type = Type);
    TreeWidgetItem(QTreeWidgetItem *parent = 0, int type = Type);

    protected:

    private:

    public slots:

    protected slots:

    private slots:

    signals:
    };

    #endif // TREEWIDGETITEM_H
    @

    @
    #include "treewidgetitem.h"

    TreeWidgetItem::TreeWidgetItem(QTreeWidget *parent, int type) : QTreeWidgetItem(parent, type){
    }

    TreeWidgetItem::TreeWidgetItem(QTreeWidgetItem *parent, int type) : QTreeWidgetItem(parent, type){
    }
    @

    I am subclassing every other Widget without problems, I don't know where my error is...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Simple: QTreeWidgetItem is not a QObject

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • K Offline
        K Offline
        kouros
        wrote on last edited by
        #3

        Yeah and how do I reimplement it? Not very useful.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Either:

          • Don't put QObject related stuff in your sub-class
          • Inherit from both QTreeWidgetItem and QObject, which generally is a bad idea if you plan to have many data in your QTreeWidget. However if you want to do it anyway, the first class that must be inherited is QObject.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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