0

Windows 10, GammaRay v3.3, Qt 6.9, llvm_mingw
I've created module with QML files (using qt_add_qml_module). One of those file is Config.qml singleton component. This component is used by many remaining components to get global values.
External JSON contains some values, which are - during runtime and start - parsed and set in Config.qml.
I would like to investigate and check those values. Standard approach (JSON.stringify or function to parse object properties and print them) requries rebuilds to capture right moment and right hander. And even then nested properties/components in Config require additional JSON.stringify.

GammaRay attach to app and shows Scene Objects well. But Config isn't visible there.
Object section searched by Config word shows nothing. MetaObjects and MetaTypes section show Config, but only properties and types, not current value. Futhermore - SelfTotal, Incl. Total, Self Alive and Incl. Alive counters shows 0.
Config.parent in QML code returns undefined - so I don't know under which parent to look.

How to locate and see in runtime inside GammaRay values of QML or C++ Singleton?

1 Answer 1

0

QQmlEngine::singletonInstance allows to get singleton present in engine (as long it was created). After app is loaded - engine.loadFromModule(moduleUri, "Main"); - this code changes singleton parent to engine, which makes it easy to find in Object tree (under QQmlApplicationEngine).

auto configSingleton = engine.singletonInstance<QObject*>(moduleUri, componentName);
if (configSingleton) {
    qDebug() << "=> Component"<< moduleUri+":"+componentName << "is a singleton with parent " << configSingleton->parent();
    configSingleton->setParent(&engine);
}

Furthermore - qDebug() shows that by default ... parent is NULL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.