jfdesjardins2
18th December 2016, 22:50
Hello,
I want to use QML with a QStateMachine. My StateMachine can be quite complex and I want to be able to test it. I want as little logic as possible in my QML.
I am not sure if I'm on the right way, but here is what I was thinking:
- Use a QML Main with a Loader.
- Create my QStateMachine
- On state change, load the desired page through the loader.
I have trouble with the last one. How can I tell my Qml which part to load? For example, let's say I have this :
Item {
id : mainWindow
visible: true
width: 1920
height: 1080
Loader { id: pageLoader
objectName: "pageLoader"
anchors.fill:parent
source: "splashScreen/SplashScreen.qml"
}
}
Then, from my C++ code, when my StateMachine tells me to change screen, I do:
QObject* QmlStartupViewBuilder::createNextScreen()
{
QObject* root = m_engine->rootObjects()[0];
QQuickItem* loaderItem = root->findChild<QQuickItem*>("pageLoader");
loaderItem->setProperty("source", QUrl(QStringLiteral("qrc:/screens/screen2/Screen2.qml")));
}
It works, but I am not sure it is the best solution. I guess I should use a slot/signal from my ViewBuilder to call my qml. But how?
Thanks a lot.
I want to use QML with a QStateMachine. My StateMachine can be quite complex and I want to be able to test it. I want as little logic as possible in my QML.
I am not sure if I'm on the right way, but here is what I was thinking:
- Use a QML Main with a Loader.
- Create my QStateMachine
- On state change, load the desired page through the loader.
I have trouble with the last one. How can I tell my Qml which part to load? For example, let's say I have this :
Item {
id : mainWindow
visible: true
width: 1920
height: 1080
Loader { id: pageLoader
objectName: "pageLoader"
anchors.fill:parent
source: "splashScreen/SplashScreen.qml"
}
}
Then, from my C++ code, when my StateMachine tells me to change screen, I do:
QObject* QmlStartupViewBuilder::createNextScreen()
{
QObject* root = m_engine->rootObjects()[0];
QQuickItem* loaderItem = root->findChild<QQuickItem*>("pageLoader");
loaderItem->setProperty("source", QUrl(QStringLiteral("qrc:/screens/screen2/Screen2.qml")));
}
It works, but I am not sure it is the best solution. I guess I should use a slot/signal from my ViewBuilder to call my qml. But how?
Thanks a lot.