Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Cannot assign to property of a property alias in reusable component
Qt 6.12 LTS is out! See what's new in the release blog

Cannot assign to property of a property alias in reusable component

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 547 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    I'm trying to assign value to content.padding , where content is a property alias from MyButton.qml and padding is a property of content. However, the complier shows Cannot assign to non-existent property padding, which confused me a lot.

    import QtQuick
    import QtQuick.Controls
    Window{
        MyButton {
            content.padding: 10
        }
    }
    
    // MyButton.qml
    import QtQuick
    import QtQuick.Controls
    Rectangle {
        property alias content: content
        Rectangle{
            id: content
            property int padding: 0
        }
    }
    
    sierdzioS 1 Reply Last reply
    0
    • K Kamichanw

      I'm trying to assign value to content.padding , where content is a property alias from MyButton.qml and padding is a property of content. However, the complier shows Cannot assign to non-existent property padding, which confused me a lot.

      import QtQuick
      import QtQuick.Controls
      Window{
          MyButton {
              content.padding: 10
          }
      }
      
      // MyButton.qml
      import QtQuick
      import QtQuick.Controls
      Rectangle {
          property alias content: content
          Rectangle{
              id: content
              property int padding: 0
          }
      }
      
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Maybe the double-naming gets confusing for QML engine? Try this:

      property alias content: contentInternal
          Rectangle{
              id: contentInternal
      

      (Z(:^

      K 1 Reply Last reply
      0
      • sierdzioS sierdzio

        Maybe the double-naming gets confusing for QML engine? Try this:

        property alias content: contentInternal
            Rectangle{
                id: contentInternal
        
        K Offline
        K Offline
        Kamichanw
        wrote on last edited by
        #3

        @sierdzio I tried your solution, but it doesn't work.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kamichanw
          wrote on last edited by
          #4

          I believe this a defect, at least, it should be fixed in future. The only way to assign property from a property alias is assigning in runtime. Do as follows:

          MyButton {
               Component.onCompleted: content.padding = 10
          }
          
          1 Reply Last reply
          1
          • K Kamichanw has marked this topic as solved on

          • Login

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