Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. No highlighting (go to definition) for injected c++ context property into qml

No highlighting (go to definition) for injected c++ context property into qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 371 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gonpaul
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      instead of context properties you should use QML_SINGLETON.
      see https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.9 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      G 1 Reply Last reply
      1
      • ekkescornerE ekkescorner

        instead of context properties you should use QML_SINGLETON.
        see https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/

        G Offline
        G Offline
        gonpaul
        wrote on last edited by
        #3

        @ekkescorner thank you so much!

        1 Reply Last reply
        0
        • G gonpaul has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved