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"
Code:
#include <QTimer>
#include <QObject>
#include <QGraphicsObject>
#include "scribblearea.h"
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
//! [0]
{
Q_OBJECT
public:
bool zoneState;
public:
enum { Type = UserType + 15 };
{ return myPolygon; }
int type() const
{ return Type;}
void toggleState();
bool getState();
/*
public Q_SLOTS:
void start(int msec);
void start();
void stop();
public slots:
*/
private:
};
Here is "diagramitem.cpp"
Code:
#include <QtGui>
#include <QObject>
#include "diagramitem.h"
//! [0]
{
zoneState = false;
// iTimer = new QTimer();
/* QTimer *timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(toggleState()));
timer->start(1000);
*/
//QObject::connect(iTimer,SIGNAL(timeout()),scribble,SLOT(timerToggle()));
myPolygon << p.point(0) << p.point(1)<< p.point(2) << p.point(3);
setPolygon(myPolygon);
}
//! [5]
void DiagramItem::toggleState()
{
if(zoneState)
zoneState = false;
else
zoneState = true;
}
bool DiagramItem::getState()
{
return zoneState;
}
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.
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