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. QML Connections: Cannot assign to non-existent property "onMessage" using Loader how to solve error
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 8.2k 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.
  • A Offline
    A Offline
    AexAcad
    wrote on last edited by AexAcad
    #1

    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!")
                }
            }
    }
    
    raven-worxR 1 Reply Last reply
    0
    • A AexAcad

      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!")
                  }
              }
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AexAcad
        wrote on last edited by AexAcad
        #3

        @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!")
                    }
                }
        }
        
        
        raven-worxR 1 Reply Last reply
        0
        • A AexAcad

          @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!")
                      }
                  }
          }
          
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @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!")
                      }
            ....
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

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