No highlighting (go to definition) for injected c++ context property into qml
-
Metadata
- I use qt 6.7.2
- QQmlContext to inject context property
- Program works (meaning m_systemHandler's state is changing fine)
Main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> #include <QQmlContext> #include <controllers/system.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; System m_systemHandler; QQmlContext * rootcontext = engine.rootContext(); rootcontext->setContextProperty( "systemHandler", &m_systemHandler ); const QUrl url(QStringLiteral("qrc:/TeslaInfotainment/main.qml")); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }RightScreen.qml where injected class is used:
import QtQuick 2.15 import QtLocation import QtPositioning Rectangle { id: rightScreen anchors { top: parent.top right: parent.right bottom: bottomBar.top } color: "orange" width: parent.width * 2/3 Image { id: lockIcon anchors { top: parent.top left: parent.left margins: 20 } width: parent.width / 30 fillMode: Image.PreserveAspectFit source: ( systemHandler.carLocked ? "./secured-lock.png" : "./unlock.png" ) MouseArea { anchors.fill: parent onClicked: systemHandler.setCarLocked( !systemHandler.carLocked ) } } }I assume this problem should either because of my ide configuration (it is default, just after installation) or this approach to expose a class is no longer a good way. I am following a guide on youtube which was recorded 1 year ago, so idk. If someone will provide resources to read that might help solving this, it would be really great!
-
instead of context properties you should use QML_SINGLETON.
see https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/ -
instead of context properties you should use QML_SINGLETON.
see https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/@ekkescorner thank you so much!
-
G gonpaul has marked this topic as solved on