[QML+Qt CPP] How to move from Screen-to-Screen in an application?
-
Well, what I would do is to expose the "state" of each screen. Each QML screen that take reads the state and do what they need to do :)
-
Can you just show some sample code so that I can understand. I tried seeing
states
property in QML but could not find a way. It largely speaks about property changes and change in positioning etc. But I could not find changing b/w completely different screens.
[quote author="t3685" date="1379618855"]Well, what I would do is to expose the "state" of each screen. Each QML screen that take reads the state and do what they need to do :)[/quote] -
I am not talking about using QML states. But rather, your C++ could for example remember what the last artists was that was selected and expose that as property.
When the approriate QML screen is loaded, it will ask the C++ for last selected artists and show the appropriate content. -
I understand what you said. But I don't think my implementation (not yet done, in abstract stage) is going to be capable that way.
At this stage leave the state of that screen (for making work easy). At least I should know how to switch b/w the screens. -
@t3685: After reading the article you "said":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-exposecppattributes.html. I understood how we can expose properties into QML. This method is really useful when we want to create custom types into QML by registering with QML type system. Thank you for showing such a good article.
But here my requirement is quite simple. I just want to fill in data into QML elements (like Text, List, Grid etc). This would be easy by just getting the object from the QML file & setting them accordingly. Both ways (one you said & the one i'm using) have to handle the objects for each of Text/List/Image/Grid etc from C++. So, I would consider the method I'm using now is easy. Because, I need not have to create classes for each of these (Grouped Texts/List/Grid etc) again (which is a hectic job) and make them available in context, from there qml will use them directly.
Am I missing something??
Coming back to my question.. Any ideas?
-
You just need to create one C++ class for each screen. You don't need to create a class for each element. Play around and see what you find is easiest. I don't have experience using your way, so if you want to continue like that you'll have to be creative :)
-
-
Use StackView of Qt Quick Controls
-
I'm using differen approach for starting qml file:
@ QQmlApplicationEngine *engine = new QQmlApplicationEngine;if (!engine) {
qDebug() << "Error creating QQmlApplicationEngine";
return 1;
}
QQmlContext *context = engine->rootContext();
context->setContextProperty("settings", &settings);engine->load(QUrl("qml/Program/main.qml"));
QObject *topLevel = engine->rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
if ( !window ) {
qWarning("Error: Your root item has to be a Window.");
return -1;
}window->show();
return app.exec();@
-
-
[quote author="t3685" date="1379689723"]You just need to create one C++ class for each screen.[/quote] True :) It seems good. I'll try once.
-
@vladstelmahovsky: I'm using the way as in "QtQuick2 Built In types" while creating a new project in QtCreator.
How is the way you told is different from the one I'm using? Which is advantageous. -
you have more control over engine, context and root object