Nominate our 2022 Qt Champions!

QmlJS::ModelManagerInterface - getting semantic info out of QML file

  • Hi,

    Currently I'm developing plugin for Qt Creator which should give me semantic information based on user location in QML file opened in text editor (where cursor is set). For example, if we have the following QML file:
    Rectangle {
    width: 200
    height: 200
    color: "blue"

    Image {
        source: "pics/logo.png"
        anchors.centerIn: parent


    and user clicks on color:"blue" plugin should tell that it is inside Rectangle object.
    I tried to use the following code:
    const QmlJS::Snapshot snapshot = modelManager->snapshot();
    const QmlJS::Document::Ptr doc = snapshot.document(fileName);
    QmlJS::AST::Node *node = doc->ast();
    const QmlJS::Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
    qDebug() << "QML class" << scopeObject->className();

    but scopeObject returned is null. ast() and bind() of document are also null, though the document->source shows the correct source file and it is parsed. The question is how to get the scopeObject or are there any other ways to do this. I get modelManager from QMLJS::ModelManagerInterface instance.


Log in to reply