OK, the reason for the problem is, that findChild() does not check "id", it looks for "objectName" property. Thanks to http://www.lothlorien.com/kf6gpe/?p=309 . Moreover, invokeMethod() should be called after setMainQmlFile() and must not be trigered from QML (i.e. qml calls C++ function which calls javascript function) before it finishes the initialization (not even from Component.onCompleted)
@
QMetaObject::invokeMethod(
viewer->rootObject()->findChild<QObject *>("myModel"), // QML item
"test" // method
// parameters
);
@
@
PageStackWindow {
id: mainApp
...
ListModel {
id: myModel
objectName: myModel
...
function test() {
console.log("TEST OK");
}
}
Page {
...
}
}
@