PDA

View Full Version : Create dynamic QML components from within C++! How to?



jackmack
12th October 2012, 09:35
Hi all,

I have posted that thread also to QtQuick Forum but maybe somebody else here can help me.

I'm using Qt over some years but without QML. Now I want to add the flicker functionality to my applications UI.
The application logic itself is coded in C++ (inherited sockets, database classes e.g.).

My applications UI should be fully configureable for diffrent customers, what means:

Customer 1: wants to have 5 sliding pages
Customer 2: wants to have 7 sliding pages

and so on. The number of pages should be loaded by a custom xml config file in the C++ part of application.

The first trips into QML examples were successfully. The example ..\4.8.2\examples\tutorials\gettingStarted\gsQml\p arts\part2 makes exactly what I want. Yeahh!

My question here:
How I can create/adding QML elements dynamically from C++ and insert it into the QML UI?

I'm confused about that statements in the QML documentation, chapter "Dynamic Object Management in QML":

"QML provides a number of ways to dynamically create and manage QML objects. The Loader, Repeater, ListView, GridView and PathView elements all support dynamic object management. Objects can also be created and managed from C++, and this is the preferred method for hybrid QML/C++ applications (see Using QML Bindings in C++ Applications)."

And then you can read this here in "Using QML Bindings in C++ Applications":

"Warning: While it is possible to use C++ to access and manipulate QML objects deep into the object tree, we recommend that you do not take this approach outside of application testing and prototyping. One strength of QML and C++ integration is the ability to implement the QML user interface separately from the C++ logic and dataset backend, and this strategy breaks if the C++ side reaches deep into the QML components to manipulate them directly."

What next?

The QML examples uses always a fixed, known, predefined QML UI.

Can anybody make a suggestion or help me?

Thanks

alizadeh91
12th October 2012, 09:52
You can call a qml function in c++ to create a dynamic element. All of data that is required by this element can send by c++ as QVariantArray to qml