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

Лагнер, Сергей developer at lagner.ru
Sun Jan 14 10:09:22 CET 2018

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<First>("com.example", 1, 0, "First",
qmlRegisterSingletonType<Second>("com.example", 1, 0, "Second",

Now I'd like to have an access to one of them from another.
For example

void Second::method() {
// I need First * instance here

Is there any way to get qml singleton instance on C++ side, from QQmlEngine
or something?

Have a nice day.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180114/86d3431a/attachment.html>

More information about the Interest mailing list