Roman Kolesnikov
Roman Kolesnikov

Reputation: 12147

Connect to C++ signal from QML

I want to connect to C++ signals from QML like this:

action.onMouseUp = function() {
    console.log("mouse up>>");
}

And declare in my C++ object this signal:

signals:
  void mouseUp(const QPointF point);

But I'm getting QML Error: TypeError: Cannot assign to read-only property "mouseUp". What might the problem be?

Upvotes: 1

Views: 737

Answers (2)

Roman Kolesnikov
Roman Kolesnikov

Reputation: 12147

I found another solution:

Q_PROPERTY(QJSValue onMouseUp READ onMouseUp WRITE setOnMouseUp)

It works even without connect()

Upvotes: 0

Arpegius
Arpegius

Reputation: 5887

You need to call connect method of action.onMouseUp object.

action.onMouseUp.connect( function() {
    console.log("mouse up>>");
});

Upvotes: 2

Related Questions