Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Minimal required files for creating a simple Quick application
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Minimal required files for creating a simple Quick application

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Binary91
    wrote on last edited by
    #1

    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.3

    Rectangle {
    id: simpleButton
    color: "grey"
    width: 150; height: 75

    Text {
        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:

    1. the .pro file
    2. deployment.pri
    3. main.cpp
    4. main.qml
    5. 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 = app

    QT += 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.3

    Rectangle {
    id: simpleButton
    color: "grey"
    width: 150; height: 75

    Text {
        id: buttonLabel
        anchors.centerIn: parent
        text: "button label"
    }
    

    }@

    Can anyone help me with that?
    Thank you in anticipation!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Binary91
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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.

          157

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              You're Welcome :) Please mark the post as solved then ;)

              157

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved