Results 1 to 11 of 11

Thread: QGraphicsItem subclass compilation error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem subclass compilation error

    Hi,

    I have a class that inherit from QGrpahicsEllipseItem to let it emit a signal when it is selected

    Qt Code:
    1. #ifndef QDEFECTITEM_H
    2. #define QDEFECTITEM_H
    3.  
    4. #include <QGraphicsEllipseItem>
    5.  
    6. class QDefectItem : public QGraphicsEllipseItem
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. QDefectItem();
    12. ~QDefectItem();
    13.  
    14. protected:
    15. QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    16.  
    17. signals:
    18. void itemSelected(QGraphicsItem*);
    19. };
    20.  
    21. #endif // QDEFECTITEM_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "QDefectItem.h"
    2.  
    3. QDefectItem::QDefectItem()
    4. {
    5.  
    6. }
    7.  
    8. QDefectItem::~QDefectItem()
    9. {
    10.  
    11. }
    12.  
    13. QVariant QDefectItem::itemChange(GraphicsItemChange change,const QVariant &value)
    14. {
    15. if (change == QGraphicsItem::ItemSelectedChange)
    16. emit itemSelected(this);
    17. return value;
    18. }
    To copy to clipboard, switch view to plain text mode 

    This simple code returns an error when tryies to compile the generated moc file.
    Missing something?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QGraphicsItem subclass compilation error

    To make use of signal/slots the class should be derived from directly or indirectly from QObject. QGraphicsEllipseItem does not have QObject in it's inheritnace tree. One thing you can do is, multiple inheritance of QObject and QGraphicsEllipseItem
    Qt Code:
    1. class QDefectItem : public QObject, public QGraphicsEllipseItem
    2. {
    3. Q_OBJECT
    4. ...
    5. };
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    ^NyAw^ (30th January 2013)

Similar Threads

  1. QGraphicsItem subclass and accessing custom properties
    By been_1990 in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2010, 01:48
  2. Qt 4.6.2. compilation error
    By b1 in forum Installation and Deployment
    Replies: 3
    Last Post: 13th June 2010, 08:22
  3. Strange compile error in subclass
    By space_otter in forum General Programming
    Replies: 4
    Last Post: 3rd March 2010, 23:26
  4. QGraphicsItem subclass access to QGraphicsView size
    By rubenvb in forum Qt Programming
    Replies: 4
    Last Post: 23rd January 2010, 21:36

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.