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. Problem with custom component used in external QML
Forum Updated to NodeBB v4.3 + New Features

Problem with custom component used in external QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 2.3k 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.
  • H Offline
    H Offline
    Honkmueller
    wrote on last edited by
    #1

    Hello Everybody,

    I want to create a system using QML, where you can load QML from a file from anywhere on the machine.
    It works fine, until I reference a custom QML component from said file.

    Example

    CustomComp.qml

    import QtQuick 2.0
    
    Rectangle {
        property int customValue: 0
    }
    

    externalQMLFile.qml

    import QtQuick 2.0
    
    CustomComp {
        customValue: 4711
    }
    

    Using this component (located in the qml.qrc) inside e.g. the main.qml works fine as does loading an external QML.
    If I do it like in the example (custom components used in external file) I get this error:

    QQmlComponent: Component is not ready
    

    Is there a way to get this accomplished? It's kinda important to this whole project.

    Best wishes,
    Andreas

    raven-worxR 1 Reply Last reply
    0
    • H Honkmueller

      Hello Everybody,

      I want to create a system using QML, where you can load QML from a file from anywhere on the machine.
      It works fine, until I reference a custom QML component from said file.

      Example

      CustomComp.qml

      import QtQuick 2.0
      
      Rectangle {
          property int customValue: 0
      }
      

      externalQMLFile.qml

      import QtQuick 2.0
      
      CustomComp {
          customValue: 4711
      }
      

      Using this component (located in the qml.qrc) inside e.g. the main.qml works fine as does loading an external QML.
      If I do it like in the example (custom components used in external file) I get this error:

      QQmlComponent: Component is not ready
      

      Is there a way to get this accomplished? It's kinda important to this whole project.

      Best wishes,
      Andreas

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Honkmueller said in Problem with custom component used in external QML:

      externalQMLFile.qml

      import QtQuick 2.0
      
      CustomComp {
          customValue: 4711
      }
      

      this can't be your full QML code using your custom component...
      How do you include your custom component type?!
      And also how do you register it (if you do at all)?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      H 1 Reply Last reply
      0
      • T Offline
        T Offline
        TenKOhms
        wrote on last edited by
        #3

        Try putting the property outside of the rectangle

        Example CustomComp.qml

        import QtQuick 2.0
        
        property string rectColor
        
        Rectangle {
            color: rectColor
        }
        
        

        example otherFile.qml

        import QtQuick2.0
        
        CustomComp {
            anchors.fill: parent
            rectColor: "blue"
        }
        
        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @Honkmueller said in Problem with custom component used in external QML:

          externalQMLFile.qml

          import QtQuick 2.0
          
          CustomComp {
              customValue: 4711
          }
          

          this can't be your full QML code using your custom component...
          How do you include your custom component type?!
          And also how do you register it (if you do at all)?

          H Offline
          H Offline
          Honkmueller
          wrote on last edited by
          #4

          @raven-worx isn't CustomComp already registered? Or is this just the case within QMLs inside the project/qml.qrc file? Is there a way to include the CutomComp.qml into the externalQMLFile.qml?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            karlheinzreichel
            wrote on last edited by
            #5

            How shall the qml engine know where your CustomComp qml file is located?

            So take a look for QML import path to add additional directories where the qml engine looks for qml files.
            ( http://doc.qt.io/qt-5/qtqml-syntax-imports.html )

            regards
            Karl-Heinz Reichel

            H 1 Reply Last reply
            0
            • K karlheinzreichel

              How shall the qml engine know where your CustomComp qml file is located?

              So take a look for QML import path to add additional directories where the qml engine looks for qml files.
              ( http://doc.qt.io/qt-5/qtqml-syntax-imports.html )

              regards
              Karl-Heinz Reichel

              H Offline
              H Offline
              Honkmueller
              wrote on last edited by
              #6

              @karlheinzreichel Like I said: The CustomComp.qml is in the qml.qrc file/directory and works fine in any other QML file in the project. So the engine seems to know, where to find it. It just doesn't work, if I use the CustomComp in a qml that I load like this:

              QQmlComponent component(Main::AppMain::engine, QUrl::fromLocalFile(filePath));
              

              Is that a "same folder" issue?

              regards Andreas

              1 Reply Last reply
              0
              • K Offline
                K Offline
                karlheinzreichel
                wrote on last edited by
                #7

                Could you show me the contents of filePath ?

                btw: one more question : did you build your app as shadow build?

                regards
                Karl-Heinz

                H 1 Reply Last reply
                0
                • K karlheinzreichel

                  Could you show me the contents of filePath ?

                  btw: one more question : did you build your app as shadow build?

                  regards
                  Karl-Heinz

                  H Offline
                  H Offline
                  Honkmueller
                  wrote on last edited by
                  #8

                  @karlheinzreichel I tried around with import statements and it turned out, that I just had to add this on top of the externalQMLFile.qml:

                  import "qrc:/"
                  

                  That's it.

                  Thank you guys, you got me on the right track.

                  Best regards,
                  Andreas

                  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