Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Gif is not displayed while clicking the Push button.-----> Loading GIF Operation is not works properly
Forum Updated to NodeBB v4.3 + New Features

Gif is not displayed while clicking the Push button.-----> Loading GIF Operation is not works properly

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 586 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by
    #1
    #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

    jsulmJ 1 Reply Last reply
    0
    • sankarapandiyanS sankarapandiyan
      #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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      sankarapandiyanS 1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        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();
            });
        

        alt text

        test project
        https://www.dropbox.com/s/4s7qq6kfdygwa8r/LoadingGif.zip?dl=0

        sankarapandiyanS 1 Reply Last reply
        3
        • jsulmJ jsulm

          @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?

          sankarapandiyanS Offline
          sankarapandiyanS Offline
          sankarapandiyan
          wrote on last edited by
          #4

          @jsulm YEp Now its Working

          1 Reply Last reply
          0
          • mrjjM mrjj

            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();
                });
            

            alt text

            test project
            https://www.dropbox.com/s/4s7qq6kfdygwa8r/LoadingGif.zip?dl=0

            sankarapandiyanS Offline
            sankarapandiyanS Offline
            sankarapandiyan
            wrote on last edited by sankarapandiyan
            #5

            @mrjj Great now its reaaly works , Thanks a lot HAve Fun .. :-) MArked as solved

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved