My Projects contains 6 qml Files: The main.qml opens a new ApplicationWindow and declares the toolbar. It also initalizes StackView with the initalItem homescreen.qml. On the Home Screen I have different buttons which open different qml Files, via stack.push("URL"). Besides the main.qml all Files start with Item{}. I've been able to connect signals from the main.qml and the home.qml. But I've been unable to access Objects that are deeper in the stack. I don't know if I hvae to change my .cpp code to access the other objects, or if I should change the Initalization of StackView, so that all Files are loaded and accessible at the beginning. Here is the code, broke down to the very basics:
main.qml
ApplicationWindow { Rectangle{ id: homeButton objectName: "homeButton" signal qmlSignal(string msg) MouseArea { onClicked: {stack.push({item:"qrc:/home.qml}); homeButton.qmlSignal("Hello")} } } StackView{ initalItem: "qrc:/home.qml" }
}
secondframe.qml // A randomw qml File that comes after the Home Screen
Item { Rectangle{ id: test objectName: "test" signal qmlSignal(string msg) MouseArea { onClicked: {stack.push({item:"qrc:/thirdframe.qml}); test.qmlSignal("Hello")} } } }
main.cpp
QApplication app (argc, argv); QQmlEngine enigne; QQmlComponent component(&engine, QUrl(QStringLiteral("qrl:/main.qml"))); QObject *object = componet.create(); QQmlComponent newcomponent(&engine, QUrl(QStringLiteral("qrl:/secondframe.qml"))); QObject *newobject = newcomponet.create(); MyClass myClass QObject *home = object->findChild<QObject*>("homeButton"); // I'm able to connect to every Object in the main.qml or home.qml QObject::connect(home,SIGNAL(qmlSignal(Qstring)), &myClass, SLOT(cppSlot(QString))); QObject *test = newobject->findChild<QObject*>("test"); // Can't connect to the Objects in secondframe.qml QObject::connect(test,SIGNAL(qmlSignal(Qstring)), &myClass, SLOT(cppSlot(QString)));