[Interest] Adding QML code from C++ at runtime

BOUCARD Olivier boucard_olivier at yahoo.fr
Fri Dec 5 16:49:18 CET 2014


Hi Alexander,
I think you are going in the wrong direction by trying to directly modify the QML from the C++ code.Normally, QML is great because it helps to better separate the functionalities (C++) from the UI (QML).
In my opinion, you should try to represent your "woman" object as a model exposed to the QML.And then deal with adding the item directly in QML with a Model View, in worse case with some Javascript.It will be way cleaner and easier.
Olivier
 

     Le Vendredi 5 décembre 2014 12h20, Alexander Syvak <alexander.svk at gmail.com> a écrit :
   

 Hi,
here's the code attached to the e-mail.
In the method woman::add_hip() I need to add a button which refers to existing QML objects in main.qml.
In main.cpp the context and window are set to a global variable which is accessed in the method woman::add_hip().
However, after instantiating the button in the context (which is a global variable) there're errors
<Unknown File>: QML Button: Cannot anchor to an item that isn't a parent or sibling.<Unknown File>: QML Button: Cannot anchor to an item that isn't a parent or sibling.<Unknown File>: Unable to assign QQuickWindowQmlImpl to QQuickItem
How to achieve valid referencing from a dynamically created component in C++?

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141205/0f91123c/attachment.html>


More information about the Interest mailing list