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. using resources system with qml
Forum Updated to NodeBB v4.3 + New Features

using resources system with qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqt5resourceimageinterface
8 Posts 4 Posters 1.2k 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.
  • N Offline
    N Offline
    newbiSoso
    wrote on 24 Aug 2019, 19:03 last edited by newbiSoso
    #1

    I'm developing an app and in need of using images for the user interface, I have them all in the resources.qrc and they look like this:

    <RCC>
        <qresource prefix="/imgs">
            <file>assets/background.svg</file>
            <file>assets/background_1.svg</file>
            <file>assets/LOGO.png</file>
            <file>assets/Logo.svg</file>
        </qresource>
    </RCC>
    

    How do I use them?

    I tried both:

    //First trial:
    Image{
                source: "qrc:///imgs/assets/LOGO.png"
    }
    //Second Trial
    Image{
                source: "qrc:/imgs/assets/LOGO.png"
    }
    

    but nothing worked, am I missing something?

    Thanx

    S 1 Reply Last reply 19 Sept 2019, 09:58
    0
    • D Offline
      D Offline
      Darta
      wrote on 24 Aug 2019, 19:19 last edited by
      #2

      Could we see the full qml file, I think it's because you didn't put an anchors or a Layout to your images so they don't know where to be displayed or it can be cause your path is wrong, mine is like this :

       "qrc:/Ressources/Images/devices.png"
      
      N 1 Reply Last reply 24 Aug 2019, 19:26
      1
      • D Darta
        24 Aug 2019, 19:19

        Could we see the full qml file, I think it's because you didn't put an anchors or a Layout to your images so they don't know where to be displayed or it can be cause your path is wrong, mine is like this :

         "qrc:/Ressources/Images/devices.png"
        
        N Offline
        N Offline
        newbiSoso
        wrote on 24 Aug 2019, 19:26 last edited by
        #3

        @darta
        Full code:

        Image{
                    source: "qrc:/imgs/assets/LOGO.png"
                    width: 500
                    height: 500
                    anchors.centerIn: parent
        }
        

        I didn't mention them because I didn't think they are relevant.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Darta
          wrote on 24 Aug 2019, 19:58 last edited by Darta
          #4

          Yes of course but we never know,

          Sorry try that line:

              <qresource prefix="/imgs/">
          

          unstead of:

          <qresource prefix="/imgs">
          
          N 1 Reply Last reply 24 Aug 2019, 20:36
          1
          • D Darta
            24 Aug 2019, 19:58

            Yes of course but we never know,

            Sorry try that line:

                <qresource prefix="/imgs/">
            

            unstead of:

            <qresource prefix="/imgs">
            
            N Offline
            N Offline
            newbiSoso
            wrote on 24 Aug 2019, 20:36 last edited by
            #5

            @darta
            tried it but the image is still not showing

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Darta
              wrote on 24 Aug 2019, 21:21 last edited by Darta
              #6

              mine is more like this :

              <RCC>
                  <qresource prefix="/">
                      <file>imgs/assets/background.svg</file>
                      <file>imgs/assets/background_1.svg</file>
                      <file>imgs/assets/LOGO.png</file>
                      <file>imgs/assets/Logo.svg</file>
                  </qresource>
              </RCC>
              maybe try that and your files should be at the roots of the project not inside release or debug
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                svyatoslav911512
                wrote on 24 Aug 2019, 23:41 last edited by
                #7

                Define resource import in your main QML file:

                import "qrc:/res"
                

                And then specify the same path as a source:

                source: "/res/image.png"
                

                My res file:

                <RCC>
                    <qresource prefix="/">
                        <file>res/image.png</file>
                    </qresource>
                </RCC>
                

                In my case, the image is located inside res folder in / prefix.

                1 Reply Last reply
                0
                • N newbiSoso
                  24 Aug 2019, 19:03

                  I'm developing an app and in need of using images for the user interface, I have them all in the resources.qrc and they look like this:

                  <RCC>
                      <qresource prefix="/imgs">
                          <file>assets/background.svg</file>
                          <file>assets/background_1.svg</file>
                          <file>assets/LOGO.png</file>
                          <file>assets/Logo.svg</file>
                      </qresource>
                  </RCC>
                  

                  How do I use them?

                  I tried both:

                  //First trial:
                  Image{
                              source: "qrc:///imgs/assets/LOGO.png"
                  }
                  //Second Trial
                  Image{
                              source: "qrc:/imgs/assets/LOGO.png"
                  }
                  

                  but nothing worked, am I missing something?

                  Thanx

                  S Offline
                  S Offline
                  sharath
                  wrote on 19 Sept 2019, 09:58 last edited by sharath
                  #8

                  Hi @newbisoso ,

                  See this, it may help you

                  1 Reply Last reply
                  1

                  • Login

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