Qt Forum

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

    Unsolved Passing an Array of Objects from QML to C++

    QML and Qt Quick
    2
    5
    186
    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.
    • DuBu
      DuBu last edited by

      Hi,

      given the following QML expression:

      property int value: 0
      filters: [ { type: value1 } ]
      

      how can I implement the "filters" property in C++:

      Q_PROPERTY(... filters ...)
      

      ?

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @DuBu last edited by

        @DuBu
        https://doc.qt.io/qt-5/qqmllistproperty.html

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • DuBu
          DuBu last edited by

          Wow, that was quick! ;-)

          Ok, what should the type of QQmlListProperty be?

          Q_PROPERTY(QQmlListProperty<...> filters READ filters)
          
          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @DuBu last edited by

            @DuBu said in Passing an Array of Objects from QML to C++:

            Wow, that was quick! ;-)

            yes too quick. my suggestion was for QObject derived objects.
            For your case a QVariantList should be enough? Where the contained QVariants will be of type QVariantMap when they come from QML.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 1
            • DuBu
              DuBu last edited by

              Wow, QVariantList with QVariantMap as contained variants works. Thanks a lot!

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