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. "Cannot assign a value directly to a grouped property" what is it?

"Cannot assign a value directly to a grouped property" what is it?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 3.7k 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
    r3d9u11
    wrote on last edited by r3d9u11
    #1

    Hi. I'm facing with a strange error: "Cannot assign a value directly to a grouped property" when tried to add childs to my component.
    there is example of parent QML (Parent.qml):

    import QtQuick 2.9
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.2
    
    GroupBox {
        property alias menuItems: itemsList
        GridLayout {
                id: itemsList
            }
    }
    

    child QML (Child.qml):

    import QtQuick 2.9
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.2
    
    Parent {
        title: qsTr("Child's Title")
        menuItems {
            Label {
                text: "hello"
            }
        }
    }
    

    Main Form QML:

    ...
       Child {
            x: 10
            y: 10
            width: 300
            height: 300
            visible: true
        }
    ...
    

    Is it possible to add childs to parent QML via alias ?
    What I'm doing wrong?

    But application successfully runs if I remove the following code from Child.qml:

    menuItems {
        Label {
            text: "hello"
        }
    }
    

    Thanks!

    R 1 Reply Last reply
    0
    • R r3d9u11

      Hi. I'm facing with a strange error: "Cannot assign a value directly to a grouped property" when tried to add childs to my component.
      there is example of parent QML (Parent.qml):

      import QtQuick 2.9
      import QtQuick.Layouts 1.3
      import QtQuick.Controls 2.2
      
      GroupBox {
          property alias menuItems: itemsList
          GridLayout {
                  id: itemsList
              }
      }
      

      child QML (Child.qml):

      import QtQuick 2.9
      import QtQuick.Layouts 1.3
      import QtQuick.Controls 2.2
      
      Parent {
          title: qsTr("Child's Title")
          menuItems {
              Label {
                  text: "hello"
              }
          }
      }
      

      Main Form QML:

      ...
         Child {
              x: 10
              y: 10
              width: 300
              height: 300
              visible: true
          }
      ...
      

      Is it possible to add childs to parent QML via alias ?
      What I'm doing wrong?

      But application successfully runs if I remove the following code from Child.qml:

      menuItems {
          Label {
              text: "hello"
          }
      }
      

      Thanks!

      R Offline
      R Offline
      r3d9u11
      wrote on last edited by r3d9u11
      #2

      @r3d9u11 think I should use Loader, but I don't know how to add multiple objects via Loader (or something else)

      I didn't find any other way except duplicate GroupBox with all setted properties and logic to all kinds of Child.qml and load it through Loader ;-(

      1 Reply Last reply
      0
      • IntruderExcluderI Offline
        IntruderExcluderI Offline
        IntruderExcluder
        wrote on last edited by
        #3

        You can set default property if you want to add childs to a some non-obvious component. Lets say you have an CustomContainer:

        ...
        Item {
            id: root
            Text { id: label; ... }
            Column {
                id: column
            }
        }
        

        And you want childs described into CustomContainer automatically be added to Column, not inside Item. For this you can use default modificator for property:

        ...
        Item {
            id: root
            default property alias contentData: column.data
        ...
        

        So, everything described at CustomContainer will be a child of your Column.

        R 1 Reply Last reply
        1
        • IntruderExcluderI IntruderExcluder

          You can set default property if you want to add childs to a some non-obvious component. Lets say you have an CustomContainer:

          ...
          Item {
              id: root
              Text { id: label; ... }
              Column {
                  id: column
              }
          }
          

          And you want childs described into CustomContainer automatically be added to Column, not inside Item. For this you can use default modificator for property:

          ...
          Item {
              id: root
              default property alias contentData: column.data
          ...
          

          So, everything described at CustomContainer will be a child of your Column.

          R Offline
          R Offline
          r3d9u11
          wrote on last edited by
          #4

          @IntruderExcluder many thanks for that hint!
          it is a bit confusing design, but it works perfect

          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