Gif is not displayed while clicking the Push button.-----> Loading GIF Operation is not works properly
Solved
General and Desktop
-
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QMovie> #include <QLabel> #include <QTimer> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::SetValueProgress); timer->start(1000); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QMovie *movie=new QMovie("/home/adx-soft1/Desktop/Sankarapandiyan/loadinggif/loadingimage.gif"); if (!movie->isValid()) { // Something went wrong :( } // Play GIF //QLabel * label = new QLabel(); label=new QLabel(); label->setGeometry(115,60,128,128); label->setMovie(movie); label->show(); movie->start(); } void MainWindow::SetValueProgress() { //label->hide(); }
There is no error but cant able to find the gif in the Label
-
@sankarapandiyan said in Gif is not displayed while clicking the Push button.-----> Loading GIF Operation is not works properly:
movie->isValid()
what does it return?
-
Hi
To avoid managing the timer we could use
QTimerSingle shot.QMovie *movie = new QMovie(":/somegif.gif"); if (!movie->isValid()) { // Something went wrong :( return; } // Play GIF auto label = new QLabel(); // no this as we want it as a window //label->setGeometry(115,60,128,128); This moves it to top corner of screen... label->resize(128, 128); label->setMovie(movie); label->show(); movie->start(); // start time to close it after 10 secs QTimer::singleShot(10000, [label] { label->close(); label->deleteLater(); });
test project
https://www.dropbox.com/s/4s7qq6kfdygwa8r/LoadingGif.zip?dl=0