0

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??

Ary
  • 128
  • 1
  • 1
  • 11
  • 1
    Add Q_OBJECT macro to your derived class. Otherwise `moc` cannot preprocess your header file in order to create signal-slot logic. – Jepessen Oct 16 '14 at 12:16
  • Add `Q_OBJECT` macro but run `qmake` again. @Ezee, you are right. I deleted my answer. – Jablonski Oct 16 '14 at 12:24
  • Yes it works! Sorry I didn't see that thread at all before! I had already tried the Q_OBJECT macro before but had not run quake after!!!! Sorry guys for this post but thank you so much for your answers!! – Ary Oct 16 '14 at 12:40

0 Answers0