Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMovie can not change file



  • I am write a program of GIFPlayer, but I can not change gif by open file on Linux Qt 5.6.1.

    void MainWindow::on_action_open_triggered()
    {
        filename = QFileDialog::getOpenFileName(this, "open file", ".", "GIF(*.gif)");
        if(!filename.isEmpty()){
            movie->setFileName(filename);
            ui->label->setMovie(movie);
            movie->start();
        }
    }
    


  • @sonichy

    I tried the same code its working here on windows Qt 5.9.3.



  • On Windows Qt 5.8, the problem is the same.
    But I find another way to solve this problem:
    Run QMovie as background, connect frameChange, return currentPixmap()

    {
        QMovie movie = new QMovie;
        connect(movie,SIGNAL(frameChanged(int)),this,SLOT(frameChange(int)));
    }
    
    void MainWindow::loadImage(QString spath)
    {
        movie->stop();
        QString MIME = QMimeDatabase().mimeTypeForFile(spath).name();
        if(MIME == "image/gif"){
            movie->setFileName(spath);
            movie->start();
        }else{
            // bmp, jpg, png...
        }
    }
    
    void MainWindow::frameChange(int fn)
    {
        ui->label->setPixmap(movie->currentPixmap());
    }
    

Log in to reply