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. [solved] Non-visual object in QML
Forum Updated to NodeBB v4.3 + New Features

[solved] Non-visual object in QML

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 6.6k 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.
  • I Offline
    I Offline
    imihajlov
    wrote on last edited by
    #1

    Is it possible to make a non-visual QML component which holds properties and nested elements? I've tried the following code, but it's an error "Component elements may not contain properties other than id":
    @
    Component {
    property int aProperty: 5
    onAPropertyChanged: {
    someCode();
    }
    NestedObject {
    }
    }
    @

    I've also tried QtObject instead of Component, but there is another error with it: "Cannot assign to non-existent default property".
    Item works fine, but it is visual. I don't need visual.

    1 Reply Last reply
    1
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      A QtObject does not have a children property, which is why it cannot have nested elements. I guess you could create an element, e.g. MyQtObject, that is a QtObject with a children default property, just like Item, but with a list of MyQtObject instead of a list of Item. And then create your element using MyQtObject.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        imihajlov
        wrote on last edited by
        #3

        [quote author="ludde" date="1337760916"]A QtObject does not have a children property, which is why it cannot have nested elements.[/quote]
        Thank you, ludde! Finally I've understood about default children property.
        I changed my code to the following:
        @
        QtObject {
        property int aProperty: 5
        onAPropertyChanged: {
        someCode();
        }
        property variant nested: NestedObject {
        }
        }
        @

        It works!

        1 Reply Last reply
        1
        • L Offline
          L Offline
          ludde
          wrote on last edited by
          #4

          Not exactly what I suggested, but that should work too, I guess!

          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