[Development] QQmlEngine and ObjectOwnership

Alberto Mardegan mardy at users.sourceforge.net
Tue Apr 28 19:12:35 CEST 2015


Hi Massimo,

On 04/28/2015 07:46 AM, Massimo Callegari wrote:
> I just wanted to share my specific(?) case so if someone stumbles on it, they can find the solution out of the box :)

I also stumbled on this problem once. Luckily, the documentation is 
quite clear on this -- the problem is that it's not that easy to find 
it. :-)
http://doc.qt.io/qt-5/qqmlengine.html#ObjectOwnership-enum

Note that regardless what you think of these heuristics, it's too late 
to change them: existing applications will either start crashing or 
leaking memory, so it's a no-go.

> I am wondering though, in a multi-context application, where you have a MainView.qml with a big
> Loader that changes context when clicking on some buttons, where do you place "shared" Items that
> need to be accessed by a context that don't know anything about the other contexts ?

This, and what you previously wrote (that these objects stay alive for 
the whole lifetime of the app) makes me think that you probably want to 
register your objects as singletons:

http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterSingletonType

Ciao,
   Alberto




More information about the Development mailing list