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. QML Types from C++ terrible things: singletons, lists and constants
Forum Updated to NodeBB v4.3 + New Features

QML Types from C++ terrible things: singletons, lists and constants

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 418 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.
  • M Offline
    M Offline
    morte
    wrote on last edited by morte
    #1

    1. Singletons with lists. If there is QML type with QQmlListProperty eg. MyType registered as qmlRegisterSingletonType<MyType>("org.examples", 1, 0, "MyType") which has QmlListProperty<MyListElement> - myList. What syntax i should use at QML side to assign something to MyType.myList?

    Syntax like that don't works:

    MyType.myList = [
      MyListElement {
        id: elem1
      } 
    ]
    
    

    It works that way (Qt.createQmlComponent also can be used):

    Component.onCompleted: {
        var o = Qt.createQmlObject('import org.examples 1.0; MyListElement {}')
        MyType.myList.push(o);
    }
    

    But there is no acess to MyListElements by their id's.

    2. Constants: i see no way how to define QML type (non-singleton or singleton) at C++ side with constant properties that should be initialized at QML side when creating object

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      I believe that should work for singletons with QQmlListProperty:

      Binding {
          target: MyType
          property: "myList"
          value: [
            MyListElement {
              id: elem1
            } 
          ]
      }
      
      M 1 Reply Last reply
      0
      • GrecKoG GrecKo

        I believe that should work for singletons with QQmlListProperty:

        Binding {
            target: MyType
            property: "myList"
            value: [
              MyListElement {
                id: elem1
              } 
            ]
        }
        
        M Offline
        M Offline
        morte
        wrote on last edited by
        #3

        @GrecKo no, that don't works: qrc:/main.qml:25 Cannot assign multiple values to a singular property

        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