I created a class that derives from QObject
and QGraphicsPixmapItem
, my goal is to display multiple different fire images to make a kind of gif so I use a Timer and the connect function, but my images do not display and I have this error:
QObject::connect: No such slot QObject::animation()
And this is my code
class Fire: public QObject,public QGraphicsPixmapItem
{
public:
Fire: QObject(),QGraphicsPixmapItem(){
}
private:
void display() {
timer=new QTimer(this);
imageFire<<(QPixmap(":/feu1.png"))<<(QPixmap(":/feu2.png"))<<(QPixmap(":/feu3.png"))<<(QPixmap(":/feu4.png"))<<(QPixmap(":/feu5.png"));
connect(timer, SIGNAL(timeout()),this, SLOT(animation()));
timer->start(1000);
//image.load(":/feu1.png");
//this->setPixmap(image);
QPixmap image;
QList<QPixmap> imageFire;
QTimer *timer;
int i;
private slots:
void animation(){
/* foreach (QPixmap pix, imageFire) {
this->setPixmap(pix);
}*/
image=imageFire.at(i);
this->setPixmap(image);
i++;
if(i==imageFire.size()){
i=0;
}
}
};
If I understood correctly it's because QGrpahicPixmapItem
doesn't inherited from QObject
, So I tried to inherit my class Fire from QGraphicsObject
but the thing is this class doesn't allow me to use the setPixmap()
function!
So how can I pass trough this problem while using the QGraphicPixmapItem class??