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. Loader cannot be created inside Component def?
QtWS25 Last Chance

Loader cannot be created inside Component def?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
loaderqml type
4 Posts 3 Posters 519 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.
  • R Offline
    R Offline
    Rajeesh_Raveendran
    wrote on 17 Jun 2023, 05:28 last edited by
    #1
    Component {
        id: indicComp
        Loader {   /// This loader gives me error while compilation
            id: loaderInst
        }
        Rectangle {
            color: "red"
            width: 100
            height: 100
        }
    }
    
    J 1 Reply Last reply 18 Jun 2023, 21:01
    0
    • O Offline
      O Offline
      oria66
      wrote on 18 Jun 2023, 17:10 last edited by oria66
      #2

      You should wrap Loader and Rectangle into a Item...

      Component {
          id: indicComp
      
      Item{
          Loader { 
              id: loaderInst
          }
          Rectangle {
              color: "red"
              width: 100
              height: 100
          }
      }
      }
      

      The truth is out there

      1 Reply Last reply
      1
      • R Rajeesh_Raveendran
        17 Jun 2023, 05:28
        Component {
            id: indicComp
            Loader {   /// This loader gives me error while compilation
                id: loaderInst
            }
            Rectangle {
                color: "red"
                width: 100
                height: 100
            }
        }
        
        J Offline
        J Offline
        jeremy_k
        wrote on 18 Jun 2023, 21:01 last edited by
        #3

        @Rajeesh_Raveendran said in Loader cannot be created inside Component def?:

        Component {
            id: indicComp
            Loader {   /// This loader gives me error while compilation
        

        It helps to include the error message. A minimal working example reports Invalid component body specification, and the static analysis message in Qt Creator Components are only allowed to have a single child element. The second message clarifies the problem, which doesn't depend on the type of items instantiated by the Component.

        @oria66 said in Loader cannot be created inside Component def?:

        You should wrap Loader and Rectangle into a Item...

        Component {
            id: indicComp
        
        Item{
        

        This works, at the expense of imposing an extra Item per instance of the component. The problem can also be solved by making the Loader a child of the Rectangle, or the other way around. This preserves the Loader sizing and focus scope behavior without explicit forwarding.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        R 1 Reply Last reply 19 Jun 2023, 05:42
        1
        • J jeremy_k
          18 Jun 2023, 21:01

          @Rajeesh_Raveendran said in Loader cannot be created inside Component def?:

          Component {
              id: indicComp
              Loader {   /// This loader gives me error while compilation
          

          It helps to include the error message. A minimal working example reports Invalid component body specification, and the static analysis message in Qt Creator Components are only allowed to have a single child element. The second message clarifies the problem, which doesn't depend on the type of items instantiated by the Component.

          @oria66 said in Loader cannot be created inside Component def?:

          You should wrap Loader and Rectangle into a Item...

          Component {
              id: indicComp
          
          Item{
          

          This works, at the expense of imposing an extra Item per instance of the component. The problem can also be solved by making the Loader a child of the Rectangle, or the other way around. This preserves the Loader sizing and focus scope behavior without explicit forwarding.

          R Offline
          R Offline
          Rajeesh_Raveendran
          wrote on 19 Jun 2023, 05:42 last edited by
          #4

          @jeremy_k said in Loader cannot be created inside Component def?:

          Components are only allowed to have a single child element

          I understood.

          Components are only allowed to have a single child element

          1 Reply Last reply
          0
          • R Rajeesh_Raveendran has marked this topic as solved on 19 Jun 2023, 05:43

          1/4

          17 Jun 2023, 05:28

          • Login

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