I cannot use signals just because call to JS must be in synchronous manner.
Signals in Qt by default are actually synchronous. When you emit a signal, all connected slots are called right away, and the emit statement only returns when all slots have executed.
So in your case, make MyItem
emit a signal and connect to that signal in QML.
(The only exception is in multithreaded code, but I assume your MyItem
instance lives in the same thread as the QML engine)
You can of course do it the other way around, and invoke JS functions from C++. I would advocate against that, since it breaks the layering - the QML layer should access the C++ layer, and not the other way around. Anyway, to call JS functions from C++, use QMetaObject::invokeMethod. For full details, have a look at the documentation about Interacting with QML Objects from C++.