[Qt-interest] Error in class inheriting QGraphicsItem, QObject

varun singh mailthatmale at yahoo.co.in
Fri Aug 21 17:11:41 CEST 2009


hi, 
 Well thanks Thiago Macieira for your efforts, but I tried all the three options sequentially but changing the order or using QGraphicsWidget is giving the same error.
And QGraphicsObject, this class is not in the Qt I have (maybe its in commercial edition).

-Varun

>--- On Fri, 21/8/09, varun singh <mailthatmale at yahoo.co.in> wrote:
>
> From: varun singh <mailthatmale at yahoo.co.in>
> Subject: Error in class inheriting QGraphicsItem, QObject
> To: qt-interest at trolltech.com
> Date: Friday, 21 August, 2009, 10:31 AM
> 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
>
>Date: Fri, 21 Aug 2009 08:49:56 +0200
>From: Thiago Macieira <thiago.macieira at trolltech.com>
>Subject: Re: [Qt-interest] Error in class inheriting QGraphicsItem,
>    QObject
>To: qt-interest at trolltech.com
>Message-ID: <200908210849.56744.thiago.macieira at trolltech.com>
>Content-Type: text/plain; charset="utf-8"
> Hi Varun
> 
> Three suggestions for you, in increasing order of
> recommendation.
> 
> Suggestion 1:
> class t: public QObject, public QGraphicsItem
> 
> Suggestion 2:
> class t: public QGraphicsObject
> 
> Suggestion 3:
> class t: public QGraphicsWidget
> 
> -- 
> Thiago Macieira - thiago.macieira (AT) nokia.com
>   Senior Product Manager - Nokia, Qt Development
> Frameworks
>      Sandakerveien 116, NO-0402 Oslo,
> Norway
> 
> Qt Developer Days 2009 | Registration Now Open!
> Munich, Germany: Oct 12 - 14     San
> Francisco, California: Nov 2 - 4
>       http://qt.nokia.com/qtdevdays2009


      Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/




More information about the Qt-interest-old mailing list