Suppose I have simple QML plugin. Periodically I check some state of my object, and in this step I want to query QML object from c++, in this way:
Plugin code (c++)
class MyItem : public QQuickItem
{
public:
MyItem(QQuickItem *parent = 0) :
QQuickItem(parent)
{}
void timerFunction(SomeObject * obj)
{
// here I need to call QML function to validate my object, may be in this way:
callJSFunction("myFunction",obj); // that's what I need
if(obj->approved) doSomething();
}
}
QML file:
MyItem {
id: myItem
property bool someProperty
function myFunction(obj)
{
obj.approved = someProperty;
}
}
I cannot use signals just because call to JS must be in synchronous manner. I mean what I need is:
- in c++ code timer calls to function timerFunction() with object to validate
- inside timerFunction() I call to JS function and get result back
- After it I continue to execute timerFunction()
So my question - is there some way to call JS function from C++ plugin object?