Unable to load gif file in QImage



  • I am using Qt 4.5 (on VS 2008) which has been built dynamically(debug and release). I have linked my app to the <QTDIR>\plugins\imageformats\qgifd4.lib.

    I create a QImage from a gif file on disk. But the QImage returned is null. I logged the loading of the gif plugin using QT_DEBUG_PLUGINS flag. The gif plugin logs are as below

    'MyApp.exe': Loaded 'C:\Qt\VS45\qt\plugins\imageformats\qgifd4.dll', Symbols loaded.
    'MyApp.exe': Unloaded 'C:\Qt\VS45\qt\plugins\imageformats\qgifd4.dll'

    I also debugged the creation of QImage. In the function createReadHandlerHelper() the code looks like this
    QFactoryLoader *l = loader();
    QStringList keys = l->keys();

    after this when the code searches for the "gif" extension in these keys nothing is found.
    Does it mean that the gif plugin is corrupt? What am I doing wrong? Please help!! I have stuck here for a long time.



  • Try this:

    In Qt folder go to <Qt Version Folder>\examples\widgets\imageviewer
    Try to load your gif images thru this application, if they are getting loaded then no prob with your plugin.

    2nd step: Check the gif path in your application. R u loading them from resource file or thru relative path, whatever is the case but using QFileInfo class you can check if the path is valid before u pass that to QImage class.



  • The imageviewer is also not able to load gif files. I am loading the files thru absolute path.



  • Check gif files are ok

    Try to create qrc (qt resource file) Add file into it

    Then load it.

    Also if possible update your version.



  • I have upgraded to 4.6.3 , and now the QImage objects loads the gif file properly. But I am unable to render it in a TableView cell. I have a custom model for the view whose data function has the following pseudo code

    QVariant data()
    {
    if (role== displayrole)
    return QVariant(QImage(gifFilePath));
    else
    return QVariant();
    }



  • Start new thread



  • After reading the documentation again, I figured out that it should be the decoration role and not the display role for the gif to render.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.