Results 1 to 3 of 3

Thread: Multiple Inheritance problems when inheriting from QGraphicsPolygonItem and QObject

  1. #1
    Join Date
    Oct 2012
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Multiple Inheritance problems when inheriting from QGraphicsPolygonItem and QObject

    I have a QGraphicsViewScene that displays a few QGraphicsPolygonItems. I created a class called DiagramItem that is based on QgraphicsPolygonItems. I wanted each polygon item to toggle it's "state" every 10 seconds after it was created. So I added a "state" member to my DiagramItem class called "zoneState."

    I saw that for a QTimer to work, it had to be a QObject. So I added QObject as one of the base classes and added the macro Q_OBJECT to the header class. Now it fails to compile. It gives me the error: "undefined reference to 'vtable for DiagramItem.' What is going on? It seems like it should be something pretty basic. Please advise!




    Here is my header file "diagramitem.h"

    Qt Code:
    1. #include <QTimer>
    2. #include <QObject>
    3. #include <QGraphicsObject>
    4.  
    5. #include "scribblearea.h"
    6.  
    7. QT_BEGIN_NAMESPACE
    8. class QPixmap;
    9. class QTextEdit;
    10. class QMenu;
    11. class QPainter;
    12. class QWidget;
    13. class QPolygonF;
    14. QT_END_NAMESPACE
    15.  
    16. //! [0]
    17. class DiagramItem : public QObject, public QGraphicsPolygonItem
    18. {
    19. Q_OBJECT
    20. public:
    21. QTimer* iTimer;
    22. QTime* timeValue;
    23. bool zoneState;
    24.  
    25. public:
    26. enum { Type = UserType + 15 };
    27.  
    28. DiagramItem(ScribbleArea *scribble, QGraphicsScene *scene = 0,QGraphicsItem *parent = 0);
    29. QPolygonF polygon() const
    30. { return myPolygon; }
    31.  
    32. int type() const
    33. { return Type;}
    34. void toggleState();
    35. bool getState();
    36.  
    37. /*
    38. public Q_SLOTS:
    39.   void start(int msec);
    40.   void start();
    41.   void stop();
    42.  
    43. public slots:
    44. */
    45.  
    46. private:
    47. QPolygonF myPolygon;
    48.  
    49.  
    50. };
    To copy to clipboard, switch view to plain text mode 

    Here is "diagramitem.cpp"
    Qt Code:
    1. #include <QtGui>
    2. #include <QObject>
    3.  
    4. #include "diagramitem.h"
    5.  
    6.  
    7. //! [0]
    8. DiagramItem::DiagramItem(ScribbleArea *scribble, QGraphicsScene *scene,QGraphicsItem *parent)
    9. : QGraphicsPolygonItem(parent, scene)
    10. {
    11. zoneState = false;
    12. // iTimer = new QTimer();
    13.  
    14. /* QTimer *timer = new QTimer();
    15.   connect(timer, SIGNAL(timeout()), this, SLOT(toggleState()));
    16.   timer->start(1000);
    17. */
    18.  
    19. //QObject::connect(iTimer,SIGNAL(timeout()),scribble,SLOT(timerToggle()));
    20.  
    21. QPolygon p = scribble->getPoly();
    22.  
    23. myPolygon << p.point(0) << p.point(1)<< p.point(2) << p.point(3);
    24.  
    25.  
    26. setPolygon(myPolygon);
    27. setFlag(QGraphicsItem::ItemIsMovable, true);
    28. setFlag(QGraphicsItem::ItemIsSelectable, true);
    29. setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    30. }
    31.  
    32. //! [5]
    33. void DiagramItem::toggleState()
    34. {
    35. if(zoneState)
    36. zoneState = false;
    37. else
    38. zoneState = true;
    39. }
    40.  
    41. bool DiagramItem::getState()
    42. {
    43. return zoneState;
    44.  
    45. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple Inheritance problems when inheriting from QGraphicsPolygonItem and QObje

    Rerun qmake. You need to do that each time you add the Q_OBJECT macro to an existing file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Multiple Inheritance problems when inheriting from QGraphicsPolygonItem and QObje

    Thank you, that worked. For further reading fun and limitations regarding Meta Object Compiler go here: http://doc.qt.digia.com/4.2/moc.html#limitations

Similar Threads

  1. Replies: 3
    Last Post: 31st July 2011, 01:30
  2. Replies: 1
    Last Post: 7th March 2011, 15:02
  3. Multiple inheritance with QObject
    By victor.fernandez in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2010, 17:40
  4. Possibly an inheritance problem with QObject?
    By chadkeck in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2008, 02:26
  5. subclassing/inheritance QObject problem
    By cbeall1 in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 18:49

Tags for this Thread

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.