Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to play a gif using QMovie when movie is not running means I have to check movie not running state. Check the below code. Here I am checking the movie state in if condition but here I am getting a segmentation fault. Can you please provide the solution.

QMovie *movie; // which is in global


if (movie->state() == QMovie::NotRunning) //getting segmentation fault here
{
movie = new QMovie("/root/Byjus_Once.gif");
if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label->setMovie(movie);
movie->start();
}

What I have tried:

QMovie *movie; // which is in global


if (movie->state() == QMovie::NotRunning) //getting segmentation fault here
{
movie = new QMovie("/root/Byjus_Once.gif");
if (!movie->isValid())
{
qDebug()<<"Movie is Inavlid";
}
ui->label->setMovie(movie);
movie->start();
}
Posted
Updated 15-Jul-19 22:36pm

1 solution

You are getting a segmentation fault most likely because movie pointer is the null pointer.
You could try
C++
if (movie)
{
   if (movie->state() == QMovie::NotRunning)
   {
      // ...
   }
}
else
{
   // movie has not been assigned yet
}
Did you try to debug?
 
Share this answer
 
Comments
Member 13740197 16-Jul-19 6:46am    
Thanks for the answer.

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