C++/QML architecture - a way to reproduce C++ structure in QML ?
-
Hi everybody,
I am currently trying to develop a quite important application (OS-like) with Qt 5.2 and Qt Quick 2 ; what I would like to do is to have all the logic implemented in C++, the UI being declared thanks to QML. At this point, it seems logical and the way to get around. However, I can't figure how to do it the clean way.. I've read a lot of documentation, tutorials and examples but nothing so big...
Let's explain a little what I would like to put as an architecture ; let's say we have a Scene object, which could contains an undefined number of Application objects. What I would like is to define the logic in CPP (how I load the applications from XML, what the scene should have as properties, ...) and then show the scene with QML. Also, we have to notice that Scene and Application elements should be re-used as component ; so, here is the basic idea : I'd like to define graphical styles that are common to each object with a file in QML (extending the CPP type).
For example, I could create a file with this content :
@Application {
Rectangle { ... }
}@Saying that an application should be representated as a Rectangle ; then, when I create a Scene object that have a list of Application (or one unique Application, to begin with), I would like it to be displayed automatically ('cause this is a property of Scene object). Is it even possible ? How can I do that ?
I thought that if I extend the C++ object and declare some graphical elements for it, it would be automatic.. But actually it doesn't look like that !
Maybe there is another way around ?
Thanks
-
Hello,
I am not sure what exactly you are trying to do but you can take a look the code of my project: https://github.com/strahlex/QtQuickVcp
I parse the children of my QtQuickItem recursively and check for the type. (https://github.com/strahlex/QtQuickVcp/blob/master/hal/qcomponent.cpp#L296) This way you can modify the Items directly from C++. You can also take a look at how I created new QML Items from C++ and how I let them interact in QML.Regards
Alexander