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. qml Loader local qml file access to qrc component

qml Loader local qml file access to qrc component

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

    Hello,
    I'm writing qml application. Default main page is here:

    Window {
        Item {
            id: mainItem
            Loader {
                id:pageLoader
                anchors.fill: parent
                source: "file:///"+applicationDirPath+"/Pages/"+"Test.qml"
            }
        }
    }
    
    

    I have component ImageLCD.qml in qrc:

    Image {
        property string sourceLocal
        source: "file:///"+applicationDirPath+"/Img/"+sourceLocal
    }
    

    Finaly I have TestQRC.qml in qrc:

    Rectangle {
        color:"green"
        ImageLCD{
            width: 150
            height: 150
            sourceLocal: "knife.png"
        }//*/
    }
    

    And I have same code in Test.qml file in ** local** directory "Pages" .

    When pageLoader load qrc file (TestQRC.qml") all working good.
    But When I load local qml file with same code - I got error:

    ImageLCD is not a type
    

    I need load local qml file and I need to use own components defined in QRC system. How to do this?

    Thank you

    JoeCFDJ 1 Reply Last reply
    0
    • P poucz

      Hello,
      I'm writing qml application. Default main page is here:

      Window {
          Item {
              id: mainItem
              Loader {
                  id:pageLoader
                  anchors.fill: parent
                  source: "file:///"+applicationDirPath+"/Pages/"+"Test.qml"
              }
          }
      }
      
      

      I have component ImageLCD.qml in qrc:

      Image {
          property string sourceLocal
          source: "file:///"+applicationDirPath+"/Img/"+sourceLocal
      }
      

      Finaly I have TestQRC.qml in qrc:

      Rectangle {
          color:"green"
          ImageLCD{
              width: 150
              height: 150
              sourceLocal: "knife.png"
          }//*/
      }
      

      And I have same code in Test.qml file in ** local** directory "Pages" .

      When pageLoader load qrc file (TestQRC.qml") all working good.
      But When I load local qml file with same code - I got error:

      ImageLCD is not a type
      

      I need load local qml file and I need to use own components defined in QRC system. How to do this?

      Thank you

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @poucz use qrc file to set your qml files up and load all of them from qrc

      P 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @poucz use qrc file to set your qml files up and load all of them from qrc

        P Offline
        P Offline
        poucz
        wrote on last edited by
        #3

        @JoeCFD Thank you for reply. Can you provide me some example how to load all qml from qrc??

        JoeCFDJ 1 Reply Last reply
        0
        • P poucz

          @JoeCFD Thank you for reply. Can you provide me some example how to load all qml from qrc??

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @poucz
          similar like here
          https://doc.qt.io/qt-6/resources.html

          create a qml.qrc file:

          <RCC>
              <qresource prefix="/">
                  <file>qml/main.qml</file>
                  <file>qml/MainToolBar.qml</file>
                  <file>qml/ControlPanel.qml</file>
                  <file>qml/MainScreen.qml</file>
                  <file alias="qml/CentralLogo.qml">qml/splash/CentralLogo.qml</file>
                  <file alias="qml/SplashScreen.qml">qml/splash/SplashScreen.qml</file>
              </qresource>
          </RCC>
          
          1 Reply Last reply
          0
          • JoeCFDJ JoeCFD referenced this topic on

          • Login

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