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. Complete noob to QML, why can't I load any images?
Forum Updated to NodeBB v4.3 + New Features

Complete noob to QML, why can't I load any images?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 7.0k 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
    bmarzolf
    wrote on last edited by
    #1

    I've been programming with Qt professionally for over 2 years on the C++ side. Todya I'm trying to learn QML - it's not going well. I'm trying to follow this guide https://qmlbook.github.io/ch01-meetqt/meetqt.html

    The first problem, I can't figure out how to get the images to load without using the absolute path to the image.

    source: "file:/abosolute/path/to/image.png"
    

    I've been searching the internet for an hour, apparently you can add resources in a way that allows this to be easier and match the example of just "image/background.png" but I can't find how to do this.

    I can add resources to the project by right clicking on resources and selecting "Add existing files" and go select the images, and they then show up in the side bar in QtCreator. But they still can't be found.

    What am I doing wrong? How do you add images, or for that matter, any resources to a project such that qml can use them?

    This is soooo much easier on the C++ side, I'm quite confused.

    S 1 Reply Last reply
    1
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Resources can be retrieved with qrc schema:

      source: "qrc:///images/image.jpg"
      
      1 Reply Last reply
      1
      • B Offline
        B Offline
        bmarzolf
        wrote on last edited by
        #3

        Nope, still didn't work.

        qrc:/main.qml:19:5: QML Image: Cannot open: qrc:///images/background.png
        

        What is the entire process to do this correctly? Have I added them correctly if I can see on the left side bar Resources > qml.qrc > / > images > background.png?

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by IntruderExcluder
          #4

          Step one: add resource file, lets say 'images.res'.
          Step two: add a prefix path to resource file, lets say '/images'.
          Step three: add an image to a '/images' prefix, lets say 'background.png', in project tree it will loooks like 'Resources > images.qrc > /images > background.png'.
          Step four: set source to your Image as "qrc:///images/background.png".

          1 Reply Last reply
          1
          • B bmarzolf

            I've been programming with Qt professionally for over 2 years on the C++ side. Todya I'm trying to learn QML - it's not going well. I'm trying to follow this guide https://qmlbook.github.io/ch01-meetqt/meetqt.html

            The first problem, I can't figure out how to get the images to load without using the absolute path to the image.

            source: "file:/abosolute/path/to/image.png"
            

            I've been searching the internet for an hour, apparently you can add resources in a way that allows this to be easier and match the example of just "image/background.png" but I can't find how to do this.

            I can add resources to the project by right clicking on resources and selecting "Add existing files" and go select the images, and they then show up in the side bar in QtCreator. But they still can't be found.

            What am I doing wrong? How do you add images, or for that matter, any resources to a project such that qml can use them?

            This is soooo much easier on the C++ side, I'm quite confused.

            S Offline
            S Offline
            sharath
            wrote on last edited by sharath
            #5

            Hi @bmarzolf,

            step 1: make one directory called images in your project directory,
            now your project directory should have images folder yourProjectDir/images
            step 2: copy all your images into images folder yourProjectDir/images/your_images.png
            step 3: On qt creator, right click on qml.qrc->Add existing files->go your project directory/images and add your_images.png and click open.
            step 4: Now in Image type,

            Image
            {
                 source:"images/your_images.png"
            }
            

            Thats it. Let me know your result.
            Happy coding.

            B A 2 Replies Last reply
            4
            • S sharath

              Hi @bmarzolf,

              step 1: make one directory called images in your project directory,
              now your project directory should have images folder yourProjectDir/images
              step 2: copy all your images into images folder yourProjectDir/images/your_images.png
              step 3: On qt creator, right click on qml.qrc->Add existing files->go your project directory/images and add your_images.png and click open.
              step 4: Now in Image type,

              Image
              {
                   source:"images/your_images.png"
              }
              

              Thats it. Let me know your result.
              Happy coding.

              B Offline
              B Offline
              bmarzolf
              wrote on last edited by
              #6

              @sharath

              THANK YOU! This is the only thing that worked.

              1 Reply Last reply
              0
              • S sharath

                Hi @bmarzolf,

                step 1: make one directory called images in your project directory,
                now your project directory should have images folder yourProjectDir/images
                step 2: copy all your images into images folder yourProjectDir/images/your_images.png
                step 3: On qt creator, right click on qml.qrc->Add existing files->go your project directory/images and add your_images.png and click open.
                step 4: Now in Image type,

                Image
                {
                     source:"images/your_images.png"
                }
                

                Thats it. Let me know your result.
                Happy coding.

                A Offline
                A Offline
                Arunaa G T
                wrote on last edited by Arunaa G T
                #7
                This post is deleted!
                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