Unsolved There is one segment when play gif with movie
-
Sorry, what event loop do you mean? And how to write?
-
@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:
-
To add to @KroMignon, m_app should be on the stack, there's no need to allocate it on the heap.
-
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
-
@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?
-
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?
-
@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.
-
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; }
-
@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.
-
ok, thank you!