我想使用frameChanged(int)在currentFrameNumber等于frameCount时发出信号,我的QT版本是4.7.4
QObject::connect(movie,SIGNAL(frameChanged(int)),movie,SLOT(stop()));
QMovieChild.cpp:
class QMovieChild:public QMovie
{
signals:
void newSignal();
public slots:
void onFrameChanged(int frameNumber){
if(frameNumber == this->frameCount()-2)
emit newSignal();
}
};
Monster.cpp:
void Monster::Vanishment()
{
QMovieChild *movie = new QMovieChild();
movie->setFileName("./pikaqiu.gif");
QSize size = this->getLabelPointer()->size();
movie->setScaledSize(size);
this->getLabelPointer()->setMovie(movie);
QMovie::connect(movie,SIGNAL(newSignal()),movie,SLOT(deleteLater()));
QMovie::connect(movie,SIGNAL(frameChanged(int)),movie,SLOT(onFrameChanged(int)));
movie->start();
}
答案 0 :(得分:1)
要创建一个信号,该类应该继承自QObject,如果您使用的类是QWidget,它也是有效的,因为它继承自QObject。
#ifndef QMOVIECHILD_H
#define QMOVIECHILD_H
#include <QMovie>
class QMovieChild : public QMovie
{
Q_OBJECT
public:
QMovieChild(QObject * parent = 0):QMovie(parent){
connect(this, SIGNAL(frameChanged(int)), this, SLOT(onFrameChanged(int)));
}
signals:
void newSignal();
private slots:
void onFrameChanged(int frameNumber){
if(frameNumber == frameCount()-1){
emit newSignal();
//stop();
}
}
};
#endif // QMOVIECHILD_H
使用:
QMovieChild *movie = new QMovieChild;
movie->setFileName("./pikaqiu.gif");
QMovie::connect(movie,SIGNAL(newSignal()),movie,SLOT(deleteLater()));
QSize size = getLabelPointer()->size();
movie->setScaledSize(size);
getLabelPointer()->setMovie(movie);
movie->start();