Important: Please read the Qt Code of Conduct -

[Solved] QML files and JPG image in QRC

  • I ran into a problem, when I tried to create a Windows installer from my application. Because I have several qml and image files, I put them into one resource file. I will use the Hello world program to demonstrate:

    #include <QDeclarativeEngine>
    #include <QDeclarativeContext>
    #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"

    #include "Test.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QmlApplicationViewer viewer;
    Test* test = new Test();
    return app.exec&#40;&#41;;

    import QtQuick 1.0

    Rectangle {
    width: 360
    height: 360
    Image { source: "../gfx/Desert.jpg"; anchors.fill: parent; }
    Text {
    text: "Hello World"
    anchors.centerIn: parent
    font.pixelSize: 18
    MouseArea {
    anchors.fill: parent
    onClicked: {
    <qresource prefix="/">
    When I compile from QT Creator and run everything works fine. I see a window with background image with the "Hello world" text.

    BUT: When I copy the created executable (with necessary dlls) to another machine, it won't load the image. I see only the "hello world" text with white background. What it means? It means that the compiled program finds the qml but not the image from the same QRC resource file.

    I tried almost every combination with Image source location, I mean: placed into same folder the QML and the PNG files
    source: "Desert.jpg"
    tried to load directly from QRC:
    source: "qrc:/gfx/Desert.jpg", "qrc:///gfx/Desert.jpg"

    In most cases it worked from the compiled folder, but never on the other machine. Checking the size of the executable file I suppose that it contains the image, why it doesn't loads then? Please help, did I missed something?

    [edit: code highlighted / Denis Kormalev]

  • Jpeg plugin is missing.

  • That is it!

    I just copied imageformats folder from qt/plugins to my application and it worked.

    Thank you very much!

  • You are welcome.
    Don't forget to mark thread as [solved].

Log in to reply