Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Adding an image to a simple QML app
Forum Updated to NodeBB v4.3 + New Features

Adding an image to a simple QML app

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 6.6k Views 3 Watching
  • 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.
  • T Offline
    T Offline
    tomy
    wrote on 29 Dec 2018, 17:28 last edited by tomy
    #1

    Well, it's making me cray. I've forgotten the right way and it's more than one hour wasting my time without success yet!

    1- I created an Empty Application called test_2 and added this code in main.qml:

    import QtQuick 2.12
    
    Image {
        id: root
        source: "images/background.png"
    }
    

    2- Copied the folder containing the images named images into the project folder
    3- Right click on the name of the project -> Add New -> Qt -> Qt Resource File -> Name: images
    4- Right click on the images.qrc > Add Existing folder (images)

    Now it's a screenshot too:

    0_1546104484066_Capture.PNG

    Now when running the app by Desktop, nothing will be shown!! :(

    Where did I go wrong please?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      oria66
      wrote on 29 Dec 2018, 18:58 last edited by
      #2

      Hello @tomy .

      Just an image component in your main.qml doesn't show in your application. You must wrap it in a Window component. However, I don't know why you create a new .qrc...

      Maybe this can help you, I do it with one .qrc.

      0_1546109889782_Captura.PNG

      Good luck and happy new year!

      The truth is out there

      T 1 Reply Last reply 29 Dec 2018, 20:55
      1
      • O oria66
        29 Dec 2018, 18:58

        Hello @tomy .

        Just an image component in your main.qml doesn't show in your application. You must wrap it in a Window component. However, I don't know why you create a new .qrc...

        Maybe this can help you, I do it with one .qrc.

        0_1546109889782_Captura.PNG

        Good luck and happy new year!

        T Offline
        T Offline
        tomy
        wrote on 29 Dec 2018, 20:55 last edited by
        #3

        @oria66
        Hello, and first off, Happy New Year to you too. :)
        Thanks it solved the issue and it works and looks better now.

        0_1546116800675_Capture_1.PNG

        You must wrap it in a Window component

        Is Window the only component that can solve the issue or might there be other components to wrap the Image and show the result please?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Dec 2018, 21:36 last edited by
          #4

          Hi,

          Did you try to use the qrc:/ prefix for the path ?
          Since you have two different .qrc files, I don't think (but I may be wrong) that the relative path can be used.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 29 Dec 2018, 22:15
          0
          • S SGaist
            29 Dec 2018, 21:36

            Hi,

            Did you try to use the qrc:/ prefix for the path ?
            Since you have two different .qrc files, I don't think (but I may be wrong) that the relative path can be used.

            T Offline
            T Offline
            tomy
            wrote on 29 Dec 2018, 22:15 last edited by
            #5

            @SGaist
            Hi,
            It was an issue, now solved. :)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 29 Dec 2018, 22:18 last edited by
              #6

              What issue was that ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply 29 Dec 2018, 22:19
              0
              • S SGaist
                29 Dec 2018, 22:18

                What issue was that ?

                T Offline
                T Offline
                tomy
                wrote on 29 Dec 2018, 22:19 last edited by
                #7

                @SGaist
                I've illustrated it in the first post.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 29 Dec 2018, 22:55 last edited by
                  #8

                  So it was indeed qrc: that was missing ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  T 1 Reply Last reply 30 Dec 2018, 09:25
                  0
                  • S SGaist
                    29 Dec 2018, 22:55

                    So it was indeed qrc: that was missing ?

                    T Offline
                    T Offline
                    tomy
                    wrote on 30 Dec 2018, 09:25 last edited by
                    #9

                    @SGaist
                    No dear.

                    There's no need to add another qrc file indeed. I merely added a new directory (containing the images) to the existing qrc file and wrapped the Image item by a Window item then ran the app.

                    1 Reply Last reply
                    0

                    1/9

                    29 Dec 2018, 17:28

                    • Login

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