Re: [Interest] How to get instance of qml singleton on C++ side

2018-01-16 Thread Лагнер , Сергей
Thank you for advice. Indeed, there is note about it in Qt documentation. > NOTE: A QObject singleton type instance returned from a singleton type provider is owned by the QML engine unless the object has explicit QQmlEngine::CppOwnership flag set. But I can't use exactly that way. I need an inst

Re: [Interest] How to get instance of qml singleton on C++ side

2018-01-15 Thread Pierre-Yves Siret
You could do an usual c++ singleton Foo& Foo::instance() { static Foo foo; return foo; } And use that in c++ and also in the singleton provider for QML : qmlRegisterSingletonType("com.example", 1, 0, "Foo", &Foo::create); QObject* Foo::create(QQmlEngine*, QJSEngine*) { Foo* foo = &i

Re: [Interest] How to get instance of qml singleton on C++ side

2018-01-14 Thread Лагнер , Сергей
Hi It's exactly what I need. I thought about such solution but compile new component, create instance of it... seems like huge amount of extra work. And it is kind of tricky. I was hoping the other way exists. But thank you anyway. 2018-01-14 16:41 GMT+07:00 Ben Lau : > > You may take this piec

Re: [Interest] How to get instance of qml singleton on C++ side

2018-01-14 Thread Ben Lau
You may take this piece of code as an example: https://github.com/benlau/quickflux/blob/master/qfappdispatcher.cpp#L51 On 14 January 2018 at 17:09, Лагнер, Сергей wrote: > Hello all. > I have two classes registered as qml singletons. > > > QObject * First::create(QQmlEngine*, QJSEngine*) { > re

[Interest] How to get instance of qml singleton on C++ side

2018-01-14 Thread Лагнер , Сергей
Hello all. I have two classes registered as qml singletons. QObject * First::create(QQmlEngine*, QJSEngine*) { return new First(); } QObject * Second::create(QQmlEngine*, QJSEngine*) { return new Second(); } qmlRegisterSingletonType("com.example", 1, 0, "First", &First::create); qmlRegisterSing