QmlSingletonRegisterType and QmlSingletonRegisterIstance
-
what is the difference between qmlregisterSingletotype and qmlregisterSingletoinstance...?
I didn't see much key diffrence as I go through documentation .Please help me to know the key difference ... -
Hi,
From a quick look, the former is to registry a QML type while the latter is to register an actual C++ object instance.
-
The important thing to understand is that the "singleton" that QML knows about does not necessarily have to be a singleton on the C++ side. You might already have an object that you want to make available to QML using the singleton access syntax but the object already exists and is not a singleton in the usually understood C++ sense. I find this useful because typically my C++ classes have dependencies that need to be passed in at construction, whereas
qmlRegisterSingletonType
creates the object for QML when it is needed and doesn't provide an easy means to pass in constructor arguments.Having said that, I believe that using
qmlRegisterSingletonInstance
is discouraged these days and that a certain combination of macros should be used to achieve a similar thing, but I have not switched over to this yet.