QEvent on property set in QML

211 views Asked by At

I would like to catch QEvent in my custom cpp QObject (MyObject) if some of the properties is changed (QEvent::DynamicPropertyChange):

class MyObject : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool value MEMBER mValue)

public:
    MyObject();

    bool event(QEvent *e) override
    {
        qDebug() << "EVENT RECIEVED" << e->type();
        return QObject::event(e);
    }

private:
    bool mValue = false;
};

It works great if i do this in cpp:

MyObject obj = MyObject();
obj.setProperty("val", true);

But it does not if I try to change property in QML:

MyObject {
    id: obj
}

Button{
    id: button
    text: "set value"
    onClicked: function () {
        console.log('button clicked');
        obj.value = true;
    }
}

This is a simple github example of this.

Any ideas ?

0

There are 0 answers