Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to play gif in qt cpp?

I want to show a gif on the screen until an action is finished.
As far as I understand from the examples, I tried something like this, but the gif does not appear on the screen. How can I do that?

QMovie *movie=new QMovie(":/images/loading.gif");
    if (!movie->isValid())
        {
         qDebug()<<"Movie is not valid";
        }

    // Play GIF
    QLabel *label = new QLabel(this);

    label->setMovie(movie);
    movie->start();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need an event loop. Bracket your code with a QApplication creation and exec

QApplication app(argc, argv);
QMovie movie(":/images/loading.gif");
if (!movie.isValid()) {
    qDebug() << "Movie is not valid";
}

// Play GIF
QLabel label;

label.setMovie(&movie);
movie.start();
app.exec();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading