Is emitting a signal from C++ to QML for reading a Q_PROPERTY a synchronous event?

Viewed 1789

Using Qt 5.1 I have this:

Q_PROPERTY(float d1 MEMBER data1 NOTIFY datas_changed_signal)
Q_PROPERTY(float d2 MEMBER data2 NOTIFY datas_changed_signal)

....

void setOBJ(nobj){
        obj=nobj; //these are pointers to a data structure
        data1=nobj->data1(); //assign to member of this class
        data2=nobj->data2();

        emit datas_changed_signal();
    }

My class receives a pointer to some data, nobj and then I want my QML to have access to this data. Actually nobj contains far more than just 2 data items, but I express here for simplicity.

I want to know a couple things. First, what happens when setOBJ is called often, quickly. Is there a risk that the QML will get notified but not read the MEMBER (data1 or data2) before setOBJ is called again? Could the QML miss some updates because of this? This would happen if it was asynchronous, for example. Or, can I always count on the QML getting the data every time this signal above it emitted?

Second, it seems to me there is some unnecessary overhead here in creating intermediate data members to store the data from the passed-in object nobj. I tried this instead:

    Q_PROPERTY(float d1 MEMBER obj->data1() NOTIFY datas_changed_signal)

But MOC doesn't seem to like using Q_PROPERTY in this way (doesn't compile). Would there be a similar alternative?

Update: I found this method (link) that seems like a viable alternative to Q_PROPERTY for sending data from C++ to QML, I could just send my data pieces as arguments to a QML function. Is that a good alternative?

1 Answers
Related