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. dynamically load images during runtime
Qt 6.11 is out! See what's new in the release blog

dynamically load images during runtime

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 4 Posters 3.2k Views 2 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.
  • V Offline
    V Offline
    Vyuvaraj
    wrote on last edited by Vyuvaraj
    #1

    How do I dynamically load images during runtime.
    Example: Album Art, Contact Pictures, etc.

    Currently I'm using array kind of implementation but it really requires the images to be embedded inside the executable. But I found it difficult when any new addition/deletion to the music/contact database are done.

    My C++ code reads the filename and pass the file name to the QML and it also places the file inside the "pics" folder. But still I couldn't able to see the images unless & until I load the images using qml.qrc->resource editor

    I get the below error if I don't add the file physically.
    QML Image: Cannot open: qrc:/qml/pics/Bluetooth.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Your question is not quite clear. Do you mean add new pictures at run time that were not available when you built your application ?

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

      V 1 Reply Last reply
      0
      • YunusY Offline
        YunusY Offline
        Yunus
        wrote on last edited by
        #3

        @Vyuvaraj What is the name format which C++ sends to Qml? What is it like? You may use imageprovider to send images directly to Qml

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Your question is not quite clear. Do you mean add new pictures at run time that were not available when you built your application ?

          V Offline
          V Offline
          Vyuvaraj
          wrote on last edited by
          #4

          @SGaist YES. Currently I have hardcoded the file names and included in my project. I wanted to make it dynamic, so that I reduce the number of hardcoded file names and file into the project. I'm expecting something like "looking to a specific folder where the exe is placed and using the required picture(s) during runtime".

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            How would you determine the name of the files to use in your application ?

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

            V 1 Reply Last reply
            0
            • SGaistS SGaist

              How would you determine the name of the files to use in your application ?

              V Offline
              V Offline
              Vyuvaraj
              wrote on last edited by
              #6

              @Yunus .png, .jpeg, .jpg files

              1 Reply Last reply
              0
              • rrlopezR Offline
                rrlopezR Offline
                rrlopez
                wrote on last edited by
                #7

                Hi, you can add file:// in front of the path of your files in order to load images outside qrc.
                i.e. file:///home/media/pic1.jpg or so.

                Lic-Ing. Rodrigo Lopez Gonzalez
                Embedded Software Engineer
                RidgeRun Engineering Ltd.
                www.ridgerun.com
                Email: rodrigo.lopez@ridgerun.com

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Vyuvaraj
                  wrote on last edited by
                  #8

                  @SGaist I use a template like the below
                  <AlbumDetails Name = "Album 1" Art = "Album1.jpg">
                  <Song Name = "Song 1" Artist = "Artist 1"/>
                  <Song Name = "Song 2" Artist = "Artist 2"/>
                  <Song Name = "Song 3" Artist = "Artist 1, Artist 2"/>
                  </AlbumDetails>

                  I will create a list of Songs under each Album details which also contains Album Art jpg file name.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    As @rrlopez already wrote, use the file:// scheme and you can access the files.

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

                    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