Click here to Skip to main content
14,236,142 members
Rate this:
Please Sign up or sign in to vote.
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 4 days ago

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Create a 'play function that checks the movie is valid and plays it. Then you just need something like
char* movies[] = { "/root/abc.gif", "/root/def.gif" }
for (int i = 0; ; i = i==1 ? 0 : 1)
{
    play(movies[i]);
}
   
Comments
Member 13740197 3 days ago
   
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 3 days ago
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100