PDA

View Full Version : animting images



sudheer
28th January 2008, 12:32
hello all, i have some flip images of donald duck, so i wanted to look those images as animating(motion to the duck) images , for that i had written code something like this


class scene : public QGraphicsScene
{
Q_OBJECT

public:
scene()
{ QTimer *timer = new QTimer;
connect(timer, SIGNAL(timeout()), this , SLOT(change()));
timer->start(20000);
}

public slots:
void change()
{
if(i==0)
{
QImage image("/home/sudheer/scrap/wallpapers/earlymick5.gif");
QPixmap photo(QPixmap::fromImage(image));
addPixmap(photo);
i=1;
}

else
{
QImage image("/home/sudheer/scrap/wallpapers/latemick.gif");
QPixmap photo(QPixmap::fromImage(image));
addPixmap(photo);
i=0;
}

}
public:
int i;

};

int main(int argc, char *argv[])
{

QApplication app(argc,argv);

scene *scene1 = new scene;
scene1->setSceneRect(-200, -200, 600, 600);
QGraphicsView *view = new QGraphicsView(scene1);

view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(QColor(230, 200, 167));
view->setWindowTitle("Graphics testing");
view->show();

return app.exec();
}


but while making of this project , it giving error as


g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.3.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.3.2/include/QtCore -I/usr/local/Trolltech/Qt-4.3.2/include/QtCore -I/usr/local/Trolltech/Qt-4.3.2/include/QtGui -I/usr/local/Trolltech/Qt-4.3.2/include/QtGui -I/usr/local/Trolltech/Qt-4.3.2/include -I. -I. -I. -o main.o main.cpp
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.3.2/lib -o test18 main.o -L/usr/local/Trolltech/Qt-4.3.2/lib -lQtGui -L/usr/local/Trolltech/Qt-4.3.2/lib -L/usr/X11R6/lib -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lglib-2.0 -lrt -ldl -lpthread
main.o(.text+0x3e): In function `main':
: undefined reference to `vtable for scene'
collect2: ld returned 1 exit status
make: *** [test18] Error 1

so plz give me any suggestions

ashukla
28th January 2008, 12:44
scene() is a Qt function. That may cause problem

jpn
28th January 2008, 13:02
Add #include "main.moc" at the end of your main.cpp, re-run qmake and make.

sudheer
28th January 2008, 13:52
thankq very much,
but may i know why we ne need to include "main.moc"

jpn
28th January 2008, 14:31
A tool called moc (http://doc.trolltech.com/4.3/moc.html) needs to be run on classes that contain Q_OBJECT macro. Class declarations should be placed in header files, qmake searches only header files by default. Otherwise you must trigger it by hand by including the .moc file.