Results 1 to 5 of 5

Thread: Can I subclass QTreeWidgetItem?

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Can I subclass QTreeWidgetItem?

    I tried this:
    Qt Code:
    1. class MyTreeWidgetItem : public QTreeWidgetItem
    2. {
    3. Q_OBJECT
    4. public:
    5. MyTreeWidgetItem(QTreeWidgetItem *parent);
    6. ~MyTreeWidgetItem();
    7. };
    To copy to clipboard, switch view to plain text mode 

    with these errors
    Qt Code:
    1. .\debug\moc_mytreewidgetitem.cpp(37) : error C2039: 'staticMetaObject' : is not a member of 'QTreeWidgetItem'
    2. e:\qt\4.2.2\include\qtgui\../../src/gui/itemviews/qtreewidget.h(41) : see declaration of 'QTreeWidgetItem'
    3. .\debug\moc_mytreewidgetitem.cpp(51) : error C2039: 'qt_metacast' : is not a member of 'QTreeWidgetItem'
    4. e:\qt\4.2.2\include\qtgui\../../src/gui/itemviews/qtreewidget.h(41) : see declaration of 'QTreeWidgetItem'
    5. .\debug\moc_mytreewidgetitem.cpp(56) : error C2039: 'qt_metacall' : is not a member of 'QTreeWidgetItem'
    6. e:\qt\4.2.2\include\qtgui\../../src/gui/itemviews/qtreewidget.h(41) : see declaration of 'QTreeWidgetItem'
    To copy to clipboard, switch view to plain text mode 

    I used to subclass the QGraphicsRectItem and it works well...
    class MyRectItem : public QObject, public QGraphicsRectItem
    {
    Q_OBJECT
    ...
    }

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I subclass QTreeWidgetItem?

    You also have to add QObject first in the base list.
    However, you only need the Q_OBJECT macro if you plan to add some signals/slots to this class.

    Regards

  3. The following user says thank you to marcel for this useful post:

    Shawn (2nd September 2007)

  4. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can I subclass QTreeWidgetItem?

    Quote Originally Posted by marcel View Post
    You also have to add QObject first in the base list.
    However, you only need the Q_OBJECT macro if you plan to add some signals/slots to this class.

    Regards
    Thanks very much for your immediate replay! Now it works.

    Would you mind to tell me why I should inherite QObject first? Actually I used to add it in the base list right behind QTreeWidgetItem, still it can not work.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Can I subclass QTreeWidgetItem?

    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    Shawn (3rd September 2007)

  7. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I subclass QTreeWidgetItem?

    This is required in multiple inheritance. It is a requirement of moc because it assumes the first base class is a QObject.

    Regards.

  8. The following user says thank you to marcel for this useful post:

    Shawn (3rd September 2007)

Similar Threads

  1. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51
  2. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 18:34
  3. From extends QTreeWidgetItem emit signal?
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2006, 14:54
  4. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 18:08
  5. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.