[Qt-interest] Error in class inheriting QGraphicsItem, QObject
varun singh
mailthatmale at yahoo.co.in
Fri Aug 21 07:01:09 CEST 2009
hi,
I want to achieve custom signals and slots funcionality with QGraphicsItem in my class. But doing so is giving some errors.
The code is:
***************************************
#include <QApplication>
#include <QtGui>
class t : public QGraphicsItem, public QObject
{
Q_OBJECT
public:
t();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget);
signals:
void tMoved();
public slots:
void prntmsg();
};
t::t()
{
setFlags(ItemIsMovable|ItemIsSelectable);
connect(this, SIGNAL(tMoved()), this, SLOT(prntmsg()));
}
QPainterPath t::shape() const
{
QPainterPath p;
p.addRect(boundingRect());
return p;
}
QRectF t::boundingRect() const
{
return QRectF(200, 200, 500, 500);
}
void t::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *Widget)
{
p->drawPixmap(200, 200, 34, 56, QPixmap(":images/Tanks.png"));
emit tMoved();
}
void t::prntmsg()
{
qWarning("This is Message");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
t i;
QGraphicsScene s;
s.setSceneRect(0, 0, 1250, 650);
s.addItem(&i);
s.setBackgroundBrush(QPixmap(":/images/background.jpg"));
QGraphicsView v;
v.setSceneRect(0, 0, 1250, 650);
v.setScene(&s);
v.show();
return app.exec();
}
**************************
The compiling output is:
************************************
G:\Qt\2009.02\mingw\bin\mingw32-make.exe: Entering directory `G:/Qt-Projects/Gui Appl/New Folder'
G:/Qt/2009.02/mingw/bin/mingw32-make.exe -f Makefile.Debug
mingw32-make.exe[1]: Entering directory `G:/Qt-Projects/Gui Appl/New Folder'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\Qt\2009.02\qt\include\QtCore" -I"..\..\..\Qt\2009.02\qt\include\QtGui" -I"..\..\..\Qt\2009.02\qt\include" -I"..\..\..\Qt\2009.02\qt\include\ActiveQt" -I"debug" -I"." -I"..\..\..\Qt\2009.02\qt\mkspecs\win32-g++" -o debug\main.o main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\m.exe debug/main.o debug/qrc_Resources.o -L"g:\Qt\2009.02\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make.exe[1]: Leaving directory `G:/Qt-Projects/Gui Appl/New Folder'
G:\Qt\2009.02\mingw\bin\mingw32-make.exe: Leaving directory `G:/Qt-Projects/Gui Appl/New Folder'
debug/main.o(.text+0x180): In function `ZN1tC2Ev':
G:/Qt-Projects/Gui Appl/New Folder/main.cpp:21: undefined reference to `vtable for t'
debug/main.o(.text+0x18c):G:/Qt-Projects/Gui Appl/New Folder/main.cpp:21: undefined reference to `vtable for t'
debug/main.o(.text+0x312): In function `ZN1tC1Ev':
G:/Qt-Projects/Gui Appl/New Folder/main.cpp:21: undefined reference to `vtable for t'
debug/main.o(.text+0x31e):G:/Qt-Projects/Gui Appl/New Folder/main.cpp:21: undefined reference to `vtable for t'
debug/main.o(.text+0x6ba): In function `ZN1t5paintEP8QPainterPK24QStyleOptionGraphicsItemP7QWidget':
G:/Qt-Projects/Gui Appl/New Folder/main.cpp:41: undefined reference to `t::tMoved()'
debug/main.o(.text$_ZN1tD1Ev[t::~t()]+0x3a): In function `ZNK6QFlagsIN13QGraphicsItem16GraphicsItemFlagEEorES1_':
G:/Qt-Projects/Gui Appl/New Folder/../../../Qt/2009.02/qt/include/QtCore/../../src/corelib/global/qglobal.h: undefined reference to `vtable for t'
debug/main.o(.text$_ZN1tD1Ev[t::~t()]+0x46):G:/Qt-Projects/Gui Appl/New Folder/../../../Qt/2009.02/qt/include/QtCore/../../src/corelib/global/qglobal.h: undefined reference to `vtable for t'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\m.exe] Error 1
G:\Qt\2009.02\mingw\bin\mingw32-make.exe: *** [debug] Error 2
Exited with code 2.
Error while building project m
When executing build step 'Make'
*****************************************
The thing works fine if I comment Q_OBJECT macro definition and signals part.
Am I missing something or am I trying it in the wrong way?
-Varun
Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com
More information about the Qt-interest-old
mailing list