【发布时间】:2016-06-08 04:31:25
【问题描述】:
我正在尝试在 Qt 中使用 QMovie 来播放两个 GIF。
当一个 gif 结束时,我需要播放下一个。
问题就在这里。我想将信号连接到插槽,以便知道 GIF 动画何时结束。这是我的代码示例:
#include "abv.h"
#include "ui_abv.h"
#include "qmovie.h"
#include "qlabel.h"
#include <iostream>
#include <QString>
#include <QDebug>
#include <QObject>
using namespace std;
abv::abv(QWidget *parent) :
QDialog(parent, Qt::FramelessWindowHint),
ui(new Ui::abv)
{
QString project = projectGifs();//projectGifs() is a function stated in my header that sends over a randomly selected gif
QMovie* movie = new QMovie(project);
if (!movie->isValid())
{
cout << "The gif is not valid!!!";
}
QLabel* label = new QLabel(this);
QObject::connect(
movie, SIGNAL(frameChanged(int)),
this, SLOT(abv::abv()));//stop animation and get new animation
label->setMovie(movie);
movie->start();
}
void abv::detectEndFrame(int frameNumber)
{
if(frameNumber == (movie->frameCount()-1))
{
movie->stop();
}
}
abv::~abv()
{
delete ui;
}
在if(frameNumber == movie->frameCount()-1),我收到一条错误消息,指出电影未声明。它还指出left of '->framecount' must point to class/struct/union/generic type。
movie->stop(); 也是如此:看来我可以访问变量 movie。
由于同样的问题,我似乎也无法用新的 GIF 替换我的电影。 我该如何解决?插入新的 GIF 动画应该注意什么?
【问题讨论】: