Results 1 to 4 of 4

Thread: Signals and slots for QGraphicsEllipseItem

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Signals and slots for QGraphicsEllipseItem

    Hello!

    I would like to add signal and slot capability to a QGraphicsEllipseItem. I read that I should inherit from QObject as well, but it didn't work. This code:

    Qt Code:
    1. class ComState : public QGraphicsEllipseItem, QObject
    2. {
    3. Q_OBJECT
    4.  
    5. double comRadius;
    6.  
    7. public:
    8. ComState(QGraphicsItem *parent = 0);
    9. ~ComState(){};
    10.  
    11. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    12.  
    13. signals:
    14. void stateChangedOut();
    15. };
    16.  
    17. ComState::ComState(QGraphicsItem *parent)
    18. {
    19. comRadius = 0.05;
    20.  
    21. setFlags(QGraphicsItem::ItemIsMovable);
    22. setRect(QRectF(-comRadius, -comRadius, 2.0*comRadius, 2.0*comRadius));
    23. }
    To copy to clipboard, switch view to plain text mode 

    Produces this compile error:

    debug\moc_ComState.cpp:44: error: 'staticMetaObject' is not a member of 'QGraphicsEllipseItem'
    debug\moc_ComState.cpp: In member function 'virtual void* ComState::qt_metacast(const char*)':
    debug\moc_ComState.cpp:64: error: 'qt_metacast' is not a member of 'QGraphicsEllipseItem'
    debug\moc_ComState.cpp: In member function 'virtual int ComState::qt_metacall(QMetaObject::Call, int, void**)':
    debug\moc_ComState.cpp:69: error: 'qt_metacall' is not a member of 'QGraphicsEllipseItem'
    I would really like to make this work instead of going the QGraphicsObject way, because I'm using things that QGraphicsEllipseItem provides.
    What do I do now?

    Thanks
    Cruz

  2. #2
    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 Re: Signals and slots for QGraphicsEllipseItem

    Hi,

    Try changing the order of base classes and also use the "public" keyword as I think that the default interpretation is that it have to inherit as private

    Qt Code:
    1. class ComState : public QObject, public QGraphicsEllipseItem
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

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

    Cruz (26th June 2014)

  4. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signals and slots for QGraphicsEllipseItem

    Yes it worked!

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signals and slots for QGraphicsEllipseItem

    The orignal code also had the problem that the inheritance from QObject was private.

    ^NyAw^'s suggestion fixed both problems

    Cheers,
    _

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

    ^NyAw^ (26th June 2014)

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 12:15
  2. Signals and Slots
    By ggdev001 in forum Qt Programming
    Replies: 6
    Last Post: 20th February 2013, 12:07
  3. Qt signals slots again
    By bmpix in forum Newbie
    Replies: 4
    Last Post: 6th December 2011, 19:54
  4. QT SIGNALS and SLOTS
    By beginQT in forum Newbie
    Replies: 7
    Last Post: 23rd September 2011, 14:40
  5. Signals and Slots
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 29th July 2010, 23:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.