Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++ Struct in QML. How?
Forum Updated to NodeBB v4.3 + New Features

C++ Struct in QML. How?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 952 Views 2 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.
  • B Offline
    B Offline
    bogong
    wrote on 3 Jan 2020, 12:50 last edited by
    #1

    Hello all!
    I need to pass some structured data from QML into C++ and vice versa.

    What is the best way for it:

    • Via QVariantMap and transform it at time of appearing in C++ into struct by hand in function or in opposite direction into map from struct?
    • Declaring struct meta information in Qt Engine and use struct directly in QML? Something like this.

    Is there information about performance, maintenance, advantage or disadvantage etc?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 3 Jan 2020, 12:59 last edited by
      #2

      Use model instead.

      B 1 Reply Last reply 3 Jan 2020, 12:59
      1
      • K kuzulis
        3 Jan 2020, 12:59

        Use model instead.

        B Offline
        B Offline
        bogong
        wrote on 3 Jan 2020, 12:59 last edited by bogong 1 Mar 2020, 13:00
        #3

        @kuzulis What do you mean under the term model? And the question is about using described two options, not about anything else.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Jan 2020, 14:17 last edited by
          #4

          The answer provided on the thread will work nicely and you won't have to do the conversions yourself.

          As for performance, do your own benchmark because it will depend on your use case and what you do with your structure.

          As for @kuzulis suggestion, it refers to the the model/view paradigm. It's also a possible good solution but will depend on your particular use case.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply 3 Jan 2020, 14:50
          1
          • S SGaist
            3 Jan 2020, 14:17

            The answer provided on the thread will work nicely and you won't have to do the conversions yourself.

            As for performance, do your own benchmark because it will depend on your use case and what you do with your structure.

            As for @kuzulis suggestion, it refers to the the model/view paradigm. It's also a possible good solution but will depend on your particular use case.

            B Offline
            B Offline
            bogong
            wrote on 3 Jan 2020, 14:50 last edited by bogong 1 Mar 2020, 14:51
            #5

            @SGaist You sending me the link that posted by me from begin? Why? What about vice versa??? How the model might be related to the matter of using in QML??? the question is about using struct but not any other solution.

            1 Reply Last reply
            0
            • O Offline
              O Offline
              ODБOï
              wrote on 3 Jan 2020, 14:54 last edited by
              #6

              @bogong said in C++ Struct in QML. How?:

              related ???

              https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

              B 1 Reply Last reply 3 Jan 2020, 14:56
              0
              • O ODБOï
                3 Jan 2020, 14:54

                @bogong said in C++ Struct in QML. How?:

                related ???

                https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

                B Offline
                B Offline
                bogong
                wrote on 3 Jan 2020, 14:56 last edited by
                #7

                @LeLev Again - the question is about USING STRUCT

                K 1 Reply Last reply 3 Jan 2020, 16:00
                -1
                • B bogong
                  3 Jan 2020, 14:56

                  @LeLev Again - the question is about USING STRUCT

                  K Offline
                  K Offline
                  KroMignon
                  wrote on 3 Jan 2020, 16:00 last edited by
                  #8

                  @bogong said in C++ Struct in QML. How?:

                  USING STRUC

                  The reply is: it is NOT possible ==> Overview - QML and C++ Integration

                  To provide some C++ data or functionality to QML, it must be made available from a QObject-derived class.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  1

                  1/8

                  3 Jan 2020, 12:50

                  • Login

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