Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QML files and JPG image in QRC
QtWS25 Last Chance

[Solved] QML files and JPG image in QRC

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 11.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlackWiCKED
    wrote on last edited by
    #1

    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:

    main.cpp:
    @
    #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();
    
    viewer.engine()->rootContext()->setContextObject(test);
    
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setSource(QUrl("qrc:///qml/main.qml"));
    viewer.showExpanded();
    
    return app.exec&#40;&#41;;
    

    }
    @
    main.qml:
    @
    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: {
    Qt.quit();
    }
    }
    }
    @
    Test.qrc:
    @
    <RCC>
    <qresource prefix="/">
    <file>qml/main.qml</file>
    <file>gfx/Desert.jpg</file>
    </qresource>
    </RCC>
    @
    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.

    PLEASE NOTE:
    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"
    etc...

    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]

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Jpeg plugin is missing.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BlackWiCKED
        wrote on last edited by
        #3

        That is it!

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

        Thank you very much!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved