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. What am i missing in my loader code
QtWS25 Last Chance

What am i missing in my loader code

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
loaderrowlayoutcomponent
2 Posts 2 Posters 382 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.
  • K Offline
    K Offline
    Kyeiv
    wrote on 24 Apr 2020, 07:29 last edited by
    #1

    Hi i am trying to use a Loader on my custom RowLayout defined in MyCustomRowLayout.qml
    when i use it normally it works fine:

    Item
    {
        id:item
       MyCustomRowLayout
       {
       id:row
       property alias context: item 
       }
    }
    

    But when i try to wrap it in Component and Loader it won't display:

    Item{ id item
    	Component
    	{
    		id:componentRow
    		MyCustomRowLayout
    		{
    			id:someRow
    			property alias context: item
    		}
    
    	}
    	Loader{
    		id: loaderr
    		sourceComponent:componentRow
    	}
    }
    

    What code should i add?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MEMekaniske
      wrote on 24 Apr 2020, 14:23 last edited by
      #2

      Hey,

      If this is a direct copy of your code there is a few typos..
      id name needs to be id:name.

      Also you cannot link your customrowlayout alias to the item reference which is outside your custom component..

      "Unlike an ordinary property, an alias has the following restrictions:

      It can only refer to an object, or the property of an object, that is within the scope of the type within which the alias is declared.
      It cannot contain arbitrary JavaScript expressions
      It cannot refer to objects declared outside of the scope of its type.
      The alias reference is not optional, unlike the optional default value for an ordinary property; the alias reference must be provided when the alias is first declared.
      It cannot refer to attached properties.
      It cannot refer to properties inside a hierarchy with depth 3 or greater. "

      Look here:
      https://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#property-aliases

      So you need to do it like this, or simlar :)

          Item{
              id:item
              Component
              {
                  id:componentRow
                  Row
                  {
                      id:someRow
                      Rectangle {
                          width:500
                          height:20
                          color:"#ff1111"
                          property Item context:item
                          Text {
                              anchors.horizontalCenter: parent.horizontalCenter
                              text: "Some text.."
                          }
                      }
                  }
      
              }
              Loader{
                  id: loaderr
                  sourceComponent:componentRow
              }
          }
      
      1 Reply Last reply
      0

      2/2

      24 Apr 2020, 14:23

      • Login

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