Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is to play two gifs sequentially one after another. After second one finished again it should start the first one. Check the below code. Here I have to play abc.gif and def.gif respectively. Can you please provide the solution for this.


QMovie movie = new QMovie("/root/abc.gif");

if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label_banner->setMovie(movie);

movie->start();
ui->stackedWidget->setCurrentIndex(4);

if (movie->currentFrameNumber() == movie->frameCount()-1)
{
movie = new QMovie("/root/def.gif");

if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label_banner->setMovie(movie);

movie->start();
ui->stackedWidget->setCurrentIndex(4);
}

What I have tried:

QMovie movie = new QMovie("/root/abc.gif");

if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label_banner->setMovie(movie);

movie->start();
ui->stackedWidget->setCurrentIndex(4);

if (movie->currentFrameNumber() == movie->frameCount()-1)
{
movie = new QMovie("/root/def.gif");

if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label_banner->setMovie(movie);

movie->start();
ui->stackedWidget->setCurrentIndex(4);
}
Posted
Updated 11-Jul-19 2:30am

1 solution

Create a 'play function that checks the movie is valid and plays it. Then you just need something like
C++
char* movies[] = { "/root/abc.gif", "/root/def.gif" }
for (int i = 0; ; i = i==1 ? 0 : 1)
{
    play(movies[i]);
}
 
Share this answer
 
Comments
Member 13740197 12-Jul-19 1:30am    
Hi,

Thanks for the answer. I have tried with your code but I am unable to play GIFs.Below is the play function. I am printing i value, it is printing continuously 0 and 1 but the gif is not playing. Can you please tell me how to solve this.

void play(char *gif)
{

movie = new QMovie(gif);
if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label_banner->setMovie(movie);

movie->start();
ui->stackedWidget->setCurrentIndex(4);
}
Richard MacCutchan 12-Jul-19 2:52am    
Sorry, but I do not know QT, so I have no idea why that code is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900