Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    QML and Qt Quick
    2
    3
    168
    Loading More Posts
    • 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
      morte last edited by morte

      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 Reply Quote 0
      • GrecKo
        GrecKo Qt Champions 2018 last edited by

        I believe that should work for singletons with QQmlListProperty:

        Binding {
            target: MyType
            property: "myList"
            value: [
              MyListElement {
                id: elem1
              } 
            ]
        }
        
        M 1 Reply Last reply Reply Quote 0
        • M
          morte @GrecKo last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post