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. Issue While deleting a Movie after the Given time
Forum Updated to NodeBB v4.3 + New Features

Issue While deleting a Movie after the Given time

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 583 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 sankarapandiyan
    #1

    I have this error While compiling

    I want to stop and close the movie after the 8 seconds . How to do this ... Any suggestions
    /home/adx-soft1/Desktop/Sankarapandiyan/labelui/mainwindow.cpp:52: error: ‘movie’ is not captured
    movie->deleteLater();
    ^~~~~

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "dialog.h"
    #include "ui_dialog.h"
    #include <QMovie>
    #include <QTimer>
    #include <QStatusBar>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->labelgif->setVisible(false);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        ui->labelgif->setVisible(true);
              ui->labelgif->setAttribute(Qt::WA_TranslucentBackground);
    
    
    
           QMovie *movie = new QMovie(":/new/prefix1/somegif.gif");
               if (!movie->isValid()) {
               // Something went wrong :(
               return;
               }
    
                ui->labelgif->setMovie(movie);
                ui->labelgif->show();
                movie->start();
    
           QTimer *timer = new QTimer (this);
    
           timer->start(1000);
    
    
           QTimer::singleShot(8000,[this, &timer]{
            movie->deleteLater();
           });
    }
    
    
    
    ODБOïO 1 Reply Last reply
    0
    • sankarapandiyanS sankarapandiyan

      I have this error While compiling

      I want to stop and close the movie after the 8 seconds . How to do this ... Any suggestions
      /home/adx-soft1/Desktop/Sankarapandiyan/labelui/mainwindow.cpp:52: error: ‘movie’ is not captured
      movie->deleteLater();
      ^~~~~

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "dialog.h"
      #include "ui_dialog.h"
      #include <QMovie>
      #include <QTimer>
      #include <QStatusBar>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          ui->labelgif->setVisible(false);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::on_pushButton_clicked()
      {
          ui->labelgif->setVisible(true);
                ui->labelgif->setAttribute(Qt::WA_TranslucentBackground);
      
      
      
             QMovie *movie = new QMovie(":/new/prefix1/somegif.gif");
                 if (!movie->isValid()) {
                 // Something went wrong :(
                 return;
                 }
      
                  ui->labelgif->setMovie(movie);
                  ui->labelgif->show();
                  movie->start();
      
             QTimer *timer = new QTimer (this);
      
             timer->start(1000);
      
      
             QTimer::singleShot(8000,[this, &timer]{
              movie->deleteLater();
             });
      }
      
      
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @sankarapandiyan hi
      you have to capture movie in the QTimer::singleShot()

      why do you create a new QTimer instance ?

      you can do :

      
          QMovie *movie = new QMovie(":/new/prefix1/somegif.gif");
                  if (movie->isValid()) {
                      movie->start();
                  }
      
                  QObject::connect(movie,&QMovie::destroyed,[](){
                     qDebug()<<"movie deleted";
                  });
      
              QTimer::singleShot(3000,[&movie]{
               movie->deleteLater();
              });
      
      sankarapandiyanS 1 Reply Last reply
      2
      • ODБOïO ODБOï

        @sankarapandiyan hi
        you have to capture movie in the QTimer::singleShot()

        why do you create a new QTimer instance ?

        you can do :

        
            QMovie *movie = new QMovie(":/new/prefix1/somegif.gif");
                    if (movie->isValid()) {
                        movie->start();
                    }
        
                    QObject::connect(movie,&QMovie::destroyed,[](){
                       qDebug()<<"movie deleted";
                    });
        
                QTimer::singleShot(3000,[&movie]{
                 movie->deleteLater();
                });
        
        sankarapandiyanS Offline
        sankarapandiyanS Offline
        sankarapandiyan
        wrote on last edited by
        #3

        @LeLev Yes , The movie deleted by using delete later using signal slot ,

        But the whole window closed , But i want to close the movie only not this-> delete later ,
        But it closed both the window and movie .

        1 Reply Last reply
        0
        • sankarapandiyanS Offline
          sankarapandiyanS Offline
          sankarapandiyan
          wrote on last edited by
          #4

          alternate text)

          Above image is get by Debugging the code

          Whole window closed by default and shows , The program has unexpectedly finished.

          jsulmJ 1 Reply Last reply
          0
          • ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #5

            move your QMovie *movie to private members

            1 Reply Last reply
            0
            • sankarapandiyanS sankarapandiyan

              alternate text)

              Above image is get by Debugging the code

              Whole window closed by default and shows , The program has unexpectedly finished.

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

              @sankarapandiyan said in Issue While deleting a Movie after the Given time:

              Whole window closed by default and shows

              Your application is crashing.
              You should said that instead of saying that the window is closed because it is not the same.

              It looks like movie was already deleted.
              And do not catch the pointer by reference:

              QTimer::singleShot(8000,[movie]{
                       movie->deleteLater();
                      });
              

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

              1 Reply Last reply
              3
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @sankarapandiyan Please don't delete your posts after you have received your answer. leave your posts online so that other people can understand the thread.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                C 1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Daisyfrank
                  Banned
                  wrote on last edited by Daisyfrank
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  -1
                  • JKSHJ JKSH

                    @sankarapandiyan Please don't delete your posts after you have received your answer. leave your posts online so that other people can understand the thread.

                    C Offline
                    C Offline
                    Courtneybarrett
                    Banned
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0

                    • Login

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