Qt World Summit: Submit your Presentation

qmetaobject::invokemethod results in: "value is undefined and could not be converted to an object"

  • Hi All,

    I'm trying to combine two examples:

    1. described in the section "Exposing Methods" of the page:

    2. described in the section "Invoking QML Methods" of the page:

    Managed to combine them, the qml function "clickReturn" gets called and everything is fine till I just want to log the incoming msg on the console as it is in the 2nd example. However, when I'd like to set the text property of the text element when the qml function gets called (see qml below), I get the error: "value is undefined and could not be converted to an object". Interestingly enough, the incoming msg still gets logged on the console successfully.

    import QtQuick 2.15
    import QtQuick.Window 2.15

    Window {
    id: mainWindow
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Text {
        id: text1
        anchors.centerIn: parent
        text: qsTr("Hello World")
        color: "black"
    MouseArea {
        objectName: "mousearea"
        anchors.fill: parent
        onClicked: {
            msgBoard.postMessage("Hello from QML");
            //var result = msgBoard.postMessage("Hello from QML")
            //console.log("Result of postMessage():", result)
        function clickReturn(msg: string){


    Does anyone have any hint?


  • Ok, found the answer shortly after posting the question: had to add 'property alias aliasText1: text1.text' within the window and use that alias in the function like 'mainwindow.aliasText1=msg'.

Log in to reply