'QML AnimatedImage: Error Reading Animated Image File qrc:/myimage.gif

How to make gif files work in qt?

I get the following error:

QML AnimatedImage: Error Reading Animated Image File qrc:/untitled/images/Pivot_Wave.gif

If I run the code below:

import QtQuick

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Rectangle {
        width: parent.width
        height: parent.height
        color: 'green'

        AnimatedImage {
            id: animation

            x: 100; y: 50
            width: 200; height: 200

            source: 'images/Pivot_Wave.gif'
        }
    }

}

Here is the gif itself:

enter image description here

qrc file:

enter image description here



Solution 1:[1]

OK, I did't know that it is necessary to have a Resource Collection File in my project to load images and Qt also didn't create one automatically for me.

So I created one myself by right clicking inside the File System and then Add New... --> Qt --> Qt Resource File

I copied the example from this website https://doc.qt.io/qt-5/resources.html and adopted it to my project:

<RCC>
    <qresource prefix="/">
        <file>images/Pivot_Wave.gif</file>
    </qresource>
</RCC>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sunwarr10r