Using Loader Objects to Access C++ Methods



  • Is it possible to have QML files I load into a Loader object access C++ methods that the parent of the Loader has access to?

    @
    //Gives access to the main qml file
    this->ui->declarativeView->rootContext()->setContextProperty("appDelegate",this);
    @

    @
    //The Loader View that I would like to be able to use this method
    //Loader is a child of a Rectangle, which is the root object
    Loader {
    source: "MainNode.qml"
    anchors.centerIn: parent
    }
    @

    @
    //What I would like to do with the method in MainNode.qml
    //MouseArea is a child of a Rectangle, which is the root of the file.
    MouseArea {
    anchors.fill: parent
    onDoubleClicked: {
    parent.width: appDelegate.getScreenWidth();
    }
    }
    @

    How would I go about implementing this interaction?


  • Moderators

    Is it not working when you just run what you wrote here?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.