Unsolved C++ Struct in QML. How?
-
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?
-
Use model instead.
-
@kuzulis What do you mean under the term model? And the question is about using described two options, not about anything else.
-
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.
-
@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.
-
@bogong said in C++ Struct in QML. How?:
related ???
https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html
-
@LeLev Again - the question is about USING STRUCT
-
@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.