[SOLVED] Minimal required files for creating a simple Quick application
-
Hi,
I'm on the way to port my applications (desktop) to mobile phones (android).
I read a lot of times, that it's strongly recommended to use QML instead of desktop Qt for mobile devices, because it would avoid lots of errors, is that right?Well, I tried starting a new Qt Quick project by using the Qt Quick tutorial. The example code in the tutorial looks like that:
@import QtQuick 2.3Rectangle {
id: simpleButton
color: "grey"
width: 150; height: 75Text { id: buttonLabel anchors.centerIn: parent text: "button label" }
}@
The problem is, they "compile" or "run" the code above using qmlscene without using any other stuff (c++ source files, headers, resource files, pri files and so on...).
In my case, I'd really like to use QtCreator and so, I have to create a project.
When I do that, it creates a lot of files:- the .pro file
- deployment.pri
- main.cpp
- main.qml
- MainForm.ui.qml
When I run that project, everything works fine, but I don't think I need all those files when Qt Quick tutorial only uses one qml file.
When I remove all those files except the main.cpp (where the main.qml is loaded) and the main.qml and try to run the project, no errors occure, the executable is created and it runs, but nothing happens. There is no UI created...
Does anyone know why? What am I doing wrong?
That is my project:
.pro file:
@TEMPLATE = appQT += qml quick widgets
SOURCES += main.cpp
DISTFILES += main.qml@
main.cpp:
@#include <QApplication>
#include <QQmlApplicationEngine>int main(int argc, char *argv[])
{
QApplication app(argc, argv);QQmlApplicationEngine engine;
engine.load("main.qml");return app.exec();
}@
main.qml:
@import QtQuick 2.3Rectangle {
id: simpleButton
color: "grey"
width: 150; height: 75Text { id: buttonLabel anchors.centerIn: parent text: "button label" }
}@
Can anyone help me with that?
Thank you in anticipation! -
Hi,
bq. I read a lot of times, that it’s strongly recommended to use QML instead of desktop Qt for mobile devices, because it would avoid lots of errors, is that right?
I didn't quite get it exactly. Which errors are you referring exactly ? Any application will produce errors if it isn't coded properly.
I won't bother for the default files which are created. AFAIK all of them are required for some purpose.
On Android there won't be qmlscene to load the QML files and thus you have use QQuickView or QQmlApplicationEngine to load the files which you have already done in the example shown above.bq. ... the executable is created and it runs, but nothing happens. There is no UI created…
Does anyone know why? What am I doing wrong?If you are using Rectangle/Item as root element you should use QQuickView to load the QML file and if using QQmlApplicationEngine use Window/ApplicationWindow and dont forget to set it's visibility to true.
-
Hi and thank you for your reply! I was afraid nobody could answer this "difficult" question...
[quote]I didn’t quite get it exactly. Which errors are you referring exactly ? Any application will produce errors if it isn’t coded properly.[/quote]On I just mean that it doesn't really work using desktop applications for mobile devices, as I read it in some topics. Is that wrong?
[quote]On Android there won’t be qmlscene to load the QML files and thus you have use QQuickView or QQmlApplicationEngine to load the files which you have already done in the example shown above.
If you are using Rectangle/Item as root element you should use QQuickView to load the QML file and if using QQmlApplicationEngine use Window/ApplicationWindow and dont forget to set it’s visibility to true.[/quote]So you say it is not possible to do it without using Window/ApplicationWindow when loading the qml with QQmlApplicationEngine? I would be really happy if that was my error! I'll test it immediately! -
bq. On I just mean that it doesn’t really work using desktop applications for mobile devices, as I read it in some topics. Is that wrong?
IMO the desktop applications would run fine on Android too but with QML you get the advantage of using GPU power indirectly as QML uses scenegraph based on OpenGL ES 2.0 or OpenGL 2.0. Thus the rendering would be pretty fast.
-
Hi again,
you were right, it works fine either using QQuickview or using QQmlApplicationEngine in combination with window{}.
Thank you very much!
[quote]IMO the desktop applications would run fine on Android too but with QML you get the advantage of using GPU power indirectly as QML uses scenegraph based on OpenGL ES 2.0 or OpenGL 2.0. Thus the rendering would be pretty fast.[/quote]Ah, ok I did not know that. So I'm on the right way learning & using QML for my purposes :-P
Thank 's again!
-
You're Welcome :) Please mark the post as solved then ;)