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. Passing an Array of Objects from QML to C++

Passing an Array of Objects from QML to C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 488 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.
  • D Offline
    D Offline
    DuBu
    wrote on 19 Feb 2021, 15:16 last edited by
    #1

    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 ...)
    

    ?

    R 1 Reply Last reply 19 Feb 2021, 15:21
    0
    • D DuBu
      19 Feb 2021, 15:16

      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 ...)
      

      ?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 Feb 2021, 15:21 last edited by
      #2

      @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
      0
      • D Offline
        D Offline
        DuBu
        wrote on 19 Feb 2021, 15:25 last edited by
        #3

        Wow, that was quick! ;-)

        Ok, what should the type of QQmlListProperty be?

        Q_PROPERTY(QQmlListProperty<...> filters READ filters)
        
        R 1 Reply Last reply 19 Feb 2021, 15:27
        0
        • D DuBu
          19 Feb 2021, 15:25

          Wow, that was quick! ;-)

          Ok, what should the type of QQmlListProperty be?

          Q_PROPERTY(QQmlListProperty<...> filters READ filters)
          
          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 19 Feb 2021, 15:27 last edited by
          #4

          @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
          1
          • D Offline
            D Offline
            DuBu
            wrote on 19 Feb 2021, 15:44 last edited by
            #5

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

            1 Reply Last reply
            0

            2/5

            19 Feb 2021, 15:21

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved