如何使用信号frameChanged(int)在QT中播放QMovie一次

时间:2017-07-05 13:12:56

标签: c++ qt

如何使用frameChanged(int)来判断帧是最后一帧,我想使用该信号来阻止Qmovie播放一次而不是永久播放。

QMovie *movie = new QMovie();
movie->setFileName("C:/Qt/qtcreator-2.2.1/game/test/pikaqiu.gif");
QSize size = this->getLabelPointer()->size();
movie->setScaledSize(size);
this->getLabelPointer()->setMovie(movie);
QObject::connect(movie,SIGNAL(finished()),movie,SLOT(deleteLater()));
movie->start();
enter code here
delete this;
movie->stop();

`

1 个答案:

答案 0 :(得分:0)

您必须使用frameCount()函数来获取QMovie的帧数。

QMovie *movie = new QMovie();
movie->setFileName("download.gif");
ui->label->setMovie(movie);

connect(movie, &QMovie::frameChanged, [=](int frameNumber){
    if(frameNumber == movie->frameCount()-1){
        movie->stop();
        movie->deleteLater();
    }
});
movie->start();