1

I want to create an signal so I have an qml file with name TestCreateSignal.qml with content like this:

import QtQuick 2.0
Rectangle
{
    color: "red"
    width: 344
    height: 233
    signal sendMessage
    MouseArea
    {
        onClicked:
        {
            sendMessage();
        }
    }
}

and i want to use this signal in another qml file with name TestUseSignal.qml

import QtQuick 2.0
Rectangle
{
    TestCreateSignal
    {
        sendMessage: //Error is at this line
        {
            console.log("message sendded");
        }
    }
}

but i got error like this when i want to user that

qrc:/TestUseSignal.qml:5 Cannot assign to non-existent property "sendMessage"

Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40
mohsen
  • 1,763
  • 3
  • 17
  • 55

1 Answers1

2

According to the docs:

An object can be notified through a signal handler whenever a particular signal is emitted. A signal handler is declared with the syntax on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. The signal handler must be declared within the definition of the object that emits the signal, and the handler should contain the block of JavaScript code to be executed when the signal handler is invoked.

In your case:

TestCreateSignal
{
    onSendMessage:
    {
        console.log("message sendded");
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I have changed but it gives me : >Cannot assign to non-existent property "onSendMessage" – mohsen Dec 05 '17 at 16:10
  • How strange, I've tried it and it works. You can share your project through github, drive or similar to see which is the – eyllanesc Dec 05 '17 at 16:12
  • the problem was for. i have used name of signal onsendmessage and used that. when i chaned it to sendmessage and used onsendmessage when using it worked – mohsen Dec 05 '17 at 16:51