Solved QMovie not starting
-
Hi. I have a QMovie that is stuck in the QMovie::NotRunning state. To be specific, this is my code. The QMovie does not display on the ui, if that helps.
QMovie *movie = new QMovie("images/nope.gif"); //Read size of gif then reset size based on the ratio movie->setScaledSize(ui->loadingLabel->size()); ui->loadingLabel->setMovie(movie); ui->loadingLabel->movie()->start(); qDebug() << "welpMovie " << movie->state(); movie->setPaused(true); connect(ui->loadingLabel->movie(), SIGNAL(finished()), this, SLOT(setPaused())); qDebug() << movie->loopCount();
This is the output when this code is run:
welpMovie QMovie::NotRunning -1
Please let me know if more information is required, I am not sure where to begin. So far, I have also tried the following, which was ineffective:
movie->start(); qDebug() << "welpMovie " << movie->state();
Output:
welpMovie QMovie::NotRunning
-
@Dummie1138 said in QMovie not starting:
ui->loadingLabel->movie()->start();
qDebug() << "welpMovie " << movie->state();You are calling state() right after calling start(). This will not work - start() is asynchronous. You need to connect a slot to https://doc.qt.io/qt-6/qmovie.html#stateChanged to get state updates when they occur.
And you really should use newer Qt5 connect syntax. -
@Dummie1138 said in QMovie not starting:
ui->loadingLabel->movie()->start();
qDebug() << "welpMovie " << movie->state();You are calling state() right after calling start(). This will not work - start() is asynchronous. You need to connect a slot to https://doc.qt.io/qt-6/qmovie.html#stateChanged to get state updates when they occur.
And you really should use newer Qt5 connect syntax. -
Hi,
Beside the excellent point of @jsulm, you are using a relative path so unless you ensure that the file is beside the executable at that path when you start your application, it won't find it.