I have the following problem:
I wrote a qml-GUI and an interface class to communicate with some C++ code by connecting signals on the qml-side with slots on the c++ side. The event or button based trigger work fine, but I need one signal that has to be triggerd directly at startup. I tried it by using Component.onCompleted
from my ApplicationWindow
. Howevery,
the output "setInitDrone() called" is generated but
getInitDrone()
is never reached. The QT documentation says: "The order of running the onCompleted handlers is undefined."
Can I make sure that the signal has already been initialized when I'm trying to send it, or is there any other method instead of using Component.onCompleted?
Thanks for any help!
main.qml:
ApplicationWindow{
id: appWindow
visible: true
minimumHeight: 800
minimumWidth: 700
visibility: Window.Maximized
signal setInitDrone()
Component.onCompleted: {
setInitDrone()
print("setInitDrone() called")
}
}
qml_cpp_interface.cpp:
void Qml_cpp_interface::getInitDrone(){
qDebug() << "Cpp initDrone received";
flightserver.init();
}
groundstation.cpp:
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
//Connect with C++ code
QObject *item = engine.rootObjects().first();
Qml_cpp_interface qml_cpp_interface;
QObject::connect(item, SIGNAL(setInitDrone()), &qml_cpp_interface,SLOT(getInitDrone()));
return app.exec();