QML Connections: Cannot assign to non-existent property "onMessage" using Loader how to solve error



  • Hi,

    I am currently trying to use a Loader in my main.qml to load a suggestions.qml file from the same directory I am following the Loader documentation but I am unable to get the connections working. I keep getting the error: Cannot assign to non-existent property "onMessage" and i can't find any info on how to solve this anywhere. Please help with some example or where am i making the error ?

    Main.qml:

    import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0
    import Qt.WebSockets 1.0
    
    Rectangle {
        id: rectangledisplaybox
        anchors.fill: parent
    
            Loader {
                id: suggestionswidgetloader
                anchors.fill: parent
                visible: true;
                source: "Suggestions.qml"
                active: true;
                 focus: true;
    
                 Connections {
                    target: suggestionswidgetloader.item
                    onMessage: console.log(msg)
                    Component.onCompleted: print ("Connections Component.onCompleted")
                 }
    
            }
    }
    

    My Suggestions.qml file:

    import QtQuick 2.0
    
    Item {
    anchors.fill: parent
    
            Rectangle {
                id: suggestion1button
                width: 30
                height: 30
                signal message(string msg)
                anchors.top: parent.top
                anchors.topMargin: 30
                anchors.horizontalCenterOffset: -75
                anchors.horizontalCenter: parent.horizontalCenter
                border.color: "#1a4878"
                border.width: 1
    
                Component.onCompleted: {
                        print("Component.onCompleted")
                        suggestion1button.message("signal sent");
                    }
    
                MouseArea {
                    id: mouseArea1
                    hoverEnabled: true
                    anchors.fill: parent
                    onClicked: suggestion1button.message("clicked!")
                }
            }
    }
    

  • Moderators

    @AexAcad
    the message signal is defined in a child item of the item you are loading, but not on the item you are loading and you are using in the Connections element



  • @raven-worx
    I have added the signal to my main item and I receive the console log:
    qml: Component.onCompleted
    qml: Connections Component.onCompleted

    but when I click the mouse area in my rectangle within the loader no message is logged in onMessage: console.log(msg).

    import QtQuick 2.0
    
    Item {
    anchors.fill: parent
    signal message(string msg)
    
            Rectangle {
                id: suggestion1button
                width: 30
                height: 30
                signal message(string msg)
                anchors.top: parent.top
                anchors.topMargin: 30
                anchors.horizontalCenterOffset: -75
                anchors.horizontalCenter: parent.horizontalCenter
                border.color: "#1a4878"
                border.width: 1
    
                Component.onCompleted: {
                        print("Component.onCompleted")
                        suggestion1button.message("signal sent");
                    }
    
                MouseArea {
                    id: mouseArea1
                    hoverEnabled: true
                    anchors.fill: parent
                    onClicked: suggestion1button.message("clicked!")
                }
            }
    }
    
    

  • Moderators

    @AexAcad
    now you have 2 items with a message signal.
    You trigger the signal of the first, but connect to the signal of the second.

    Item {
    id: main
    
    signal message(string msg)
    
            Rectangle {
                id: suggestion1button
               ...
                MouseArea {
                    id: mouseArea1
                    ...
                    onClicked: main.message("clicked!")
                }
      ....
    }
    

Log in to reply
 

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