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. There is one segment when play gif with movie
Qt 6.11 is out! See what's new in the release blog

There is one segment when play gif with movie

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 913 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    Why not just start the event loop like for any Qt GUI application ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • J Offline
      J Offline
      jmdvirus
      wrote on last edited by
      #3

      Sorry, what event loop do you mean? And how to write?

      KroMignonK 1 Reply Last reply
      0
      • J jmdvirus

        Sorry, what event loop do you mean? And how to write?

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #4

        @jmdvirus said in There is one segment when play gif with movie:

        And how to write?

        Your application is not really "Qt conform", you can try this way:

        m_app = new QApplication(argc, args);
        QWidget w;
            w.show();
        QLabel label(w);
            QMovie movie(file);
            
            // to restart the movie
            QObject::connect(&movie, &QMovie::finished, m_app, [=]()
            {
                printf("rerun movie\n");
                movie.start();
            }
            );
            label.setMovie(&movie);
            movie.start();
            label.show();
            printf("movie cycle show\n");
        
            // start the event queue processing...
            m_app->exec();
        
        

        I would also suggest you to read at least those articles:

        • https://wiki.qt.io/Qt_for_Beginners
        • https://doc.qt.io/qt-5/qtexamplesandtutorials.html

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          To add to @KroMignon, m_app should be on the stack, there's no need to allocate it on the heap.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • J Offline
            J Offline
            jmdvirus
            wrote on last edited by
            #6

            Oh, yes, thank you. But I just use another way to do it

            class MovieTest : public QWidget {
                    Q_OBJECT
                public:
                    explicit MovieTest(QWidget *parent = NULL) {
                        this->setParent(parent);
                        connect(&m_movie, SIGNAL(finished()), this, SLOT(restartMovie()));
                    }
            
                    int init(const char *file) {
                        m_movie.setFileName(file);
                        return 0;
                    }
            
                    int start() {
                        m_label.setMovie(&m_movie);
                        m_movie.start();
                        return 0;
                    }
            
                public slots:
                            void restartMovie() {
                        printf("move status: [%d]\n", m_movie.state());
                        m_movie.start();
                    };
            
                protected:
                    bool event(QEvent *event) override {
                        printf("--------- get event ???[%d]\n", event->type());
                        printf("move status [%d]\n", m_movie.state());
                    }
            
                private:
                    QMovie   m_movie;
                    QLabel   m_label;
            };
            

            But the segment also exist

            KroMignonK 1 Reply Last reply
            0
            • J jmdvirus

              Oh, yes, thank you. But I just use another way to do it

              class MovieTest : public QWidget {
                      Q_OBJECT
                  public:
                      explicit MovieTest(QWidget *parent = NULL) {
                          this->setParent(parent);
                          connect(&m_movie, SIGNAL(finished()), this, SLOT(restartMovie()));
                      }
              
                      int init(const char *file) {
                          m_movie.setFileName(file);
                          return 0;
                      }
              
                      int start() {
                          m_label.setMovie(&m_movie);
                          m_movie.start();
                          return 0;
                      }
              
                  public slots:
                              void restartMovie() {
                          printf("move status: [%d]\n", m_movie.state());
                          m_movie.start();
                      };
              
                  protected:
                      bool event(QEvent *event) override {
                          printf("--------- get event ???[%d]\n", event->type());
                          printf("move status [%d]\n", m_movie.state());
                      }
              
                  private:
                      QMovie   m_movie;
                      QLabel   m_label;
              };
              

              But the segment also exist

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #7

              @jmdvirus First, always call base class constructor in you constructor, and prefere new connect syntax to detect possible typo errors on build time:

              explicit MovieTest(QWidget *parent = NULL): QWidget(parent)
                     {
                          connect(&m_movie, &QMovie::finished, this, &MovieTest::restartMovie);
                      }
              

              Second, how to do you have changed the main() function?

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jmdvirus
                wrote on last edited by
                #8

                I move connect to init function, and then change main to below

                QApplication app(argc, args);
                
                  printf("Start to show\n");
                  MovieTest m;
                  m.init(args[1]);
                  m.start();
                  m.show();
                
                  app.exec();
                

                but problem is also exist, any other need change?

                KroMignonK 1 Reply Last reply
                0
                • J jmdvirus

                  I move connect to init function, and then change main to below

                  QApplication app(argc, args);
                  
                    printf("Start to show\n");
                    MovieTest m;
                    m.init(args[1]);
                    m.start();
                    m.show();
                  
                    app.exec();
                  

                  but problem is also exist, any other need change?

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by KroMignon
                  #9

                  @jmdvirus Do you have change the constructor?

                  Because I am lazy, I made a little google search and found this => https://doc.qt.io/qt-5/qtwidgets-widgets-movie-example.html

                  I think this is a good starting point for you and will help you to understand what you are doing wrong.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jmdvirus
                    wrote on last edited by
                    #10

                    No, show is normal, it will segment fault after show some times
                    This may help to know

                    # test_qt_tips bootLoading.gif 
                    Start program
                    Start to show
                    move status: [0]
                    move status: [0]
                    Segmentation fault
                    

                    "move status" means restart show movie, but it will segment fault after how many times is unsure, maybe more, or less.

                    construct like this

                    explicit MovieTest(QWidget *parent = NULL) {
                                this->setParent(parent);
                                m_label.setParent(this);
                            }
                    
                            int init(const char *file) {
                                m_movie.setFileName(file);
                                connect(&m_movie, SIGNAL(finished()), this, SLOT(restartMovie()));
                                return 0;
                            }
                    
                    KroMignonK 1 Reply Last reply
                    0
                    • J jmdvirus

                      No, show is normal, it will segment fault after show some times
                      This may help to know

                      # test_qt_tips bootLoading.gif 
                      Start program
                      Start to show
                      move status: [0]
                      move status: [0]
                      Segmentation fault
                      

                      "move status" means restart show movie, but it will segment fault after how many times is unsure, maybe more, or less.

                      construct like this

                      explicit MovieTest(QWidget *parent = NULL) {
                                  this->setParent(parent);
                                  m_label.setParent(this);
                              }
                      
                              int init(const char *file) {
                                  m_movie.setFileName(file);
                                  connect(&m_movie, SIGNAL(finished()), this, SLOT(restartMovie()));
                                  return 0;
                              }
                      
                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by KroMignon
                      #11

                      @jmdvirus Because I am a lazy developer, I made a little Google search and found this ==> https://doc.qt.io/qt-5/qtwidgets-widgets-movie-example.html.

                      I think this is a good starting point for you application and I will help your to understand what you may have do wrong.

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1
                      • J Offline
                        J Offline
                        jmdvirus
                        wrote on last edited by
                        #12

                        ok, thank you!

                        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