Utilizing multiple QQmlContext instances and the differences between QQmlEngine, QQmlApplicationEngine and QQuickView
-
I am very new to QML and am trying to better understand the use case where I would want to have multiple QQmlContexts within my application.
I am currently designing an application which will be somewhat like a Dashboard where I am amalgamating several existing apps into one and all of the features within these apps will be accessed through various levels of this Dashboard interface. So there will be sections of features segregated out and then once you navigate to that section, there will be further break downs of features. It will be somewhat hierarchical in nature.
So this is why I thought multiple QQmlContexts would lend well to this design because of what I understand to be there hierarchical nature based on the Qt documentation I have read. There are different points of view on our team where some members are suggesting a one-to-one relationship between our models and views and having a QQmlContext for each pairing.
We are still in the somewhat preliminary stages of our UI design so I am not sure the best approach but I wanted to reach out to the community here to see what the pros and cons to using multiple or hierarchical QQmlContexts are.
This is all based on the understanding that you only ever want one QQmlEngine. But I am still unclear as to the contrasts between the use of QQmlEngine, QQmlApplicationEngine and QQuickView so a perspective on those would be greatly appreciated also based on the design I described above.
Thanks for any insight.
-
I have some project, something like file manager, where every subwindow have its own context. To achieve this I have multiple
QQmlEngine
instances. I see no problem to make any communication between them if needed. -
No, you can have only one context, which created by
QQmlEngine
, to get multiple separated context I have multiple instances of differentQQmlEngine
. -
@IntruderExcluder That's interesting because I believe I read somewhere in the QT documentation that you can have multiple QQmlContext instances assigned to the same QQmlEngine.
One of the main things we want to be able to do is have embedded "views" or Windows in our application. We feel it's logical to want to, for example, organize our bindings in separate model/view groupings. It makes sense that you would want to manage bindings in a "per view" basic. In other words, I DON"T want to have to have one QQuickView and assign all of my models through view->setContextProperty for my entire application on that one main view. There should be a way where I can logically break that up based on my view hierarchy.
Or am I looking at this the wrong way? Is there ONLY one QQuickView per application and you need to user another type of view object to break up your view into different segments, like panels which you could have in a stack panel or something like that?
Does that make sense?
-
Not sure about
QQuickView
but my experince says that it is ok to have multipleQQmlApplicationEngine
. Each engine had its own context and there was no any collision. I also was able to "talk" between this engines. You can just try with something simple. EveryQQuickView
will create its ownQQmlEngine
with oneQQmlContext
. -
@MarkGR said in Utilizing multiple QQmlContext instances and the differences between QQmlEngine, QQmlApplicationEngine and QQuickView:
@IntruderExcluder That's interesting because I believe I read somewhere in the QT documentation that you can have multiple QQmlContext instances assigned to the same QQmlEngine.
Hi,
That would be in QQmlContext's documentation.