Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A simple Qt Quick app
Forum Updated to NodeBB v4.3 + New Features

A simple Qt Quick app

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.6k 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    Hi,
    Using this example I first created an "Application > Qt Quick application project".
    I didn't change the main.cpp (and it was strange and interesting that even QML is also based on C++! Well done C++!)
    Then kept the Window part and entered the Rectangle section below that as follows:

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Rec")
    
       Rectangle {
          id: root
          x: 50; y: 10
           width: 120; height: 240
           color: "Blue"
    
           Image {
               id: triangle
               x: root.width + width/2; y: height/2
               source: "/triangle_red.png"
           }
    
           Text {
               y: 50
               width: root.width
               color: "white"
               horizontalAlignment: Text.AlignHCenter
               text: "Triangle"
           }
       }
    }
    

    The output is shown for Desktop. For other kits I just pressed the build button because I just needed the APK files.

    My questions:

    1- Is the type of the project exactly the one the book has used?
    2-Do I need to keep the Window section? If so why it's not shown in the example?
    3- Shouldn't I change anything in main.cpp?
    4- I built the project using the Arm Android kit but the size of the APK files for both Release and Debug modes are the same. I expected to have a smaller size for the Release mode. :(

    thank you.

    Arvindhan PonnusamyA jsulmJ 2 Replies Last reply
    0
    • tomyT tomy

      Hi,
      Using this example I first created an "Application > Qt Quick application project".
      I didn't change the main.cpp (and it was strange and interesting that even QML is also based on C++! Well done C++!)
      Then kept the Window part and entered the Rectangle section below that as follows:

      import QtQuick 2.6
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Rec")
      
         Rectangle {
            id: root
            x: 50; y: 10
             width: 120; height: 240
             color: "Blue"
      
             Image {
                 id: triangle
                 x: root.width + width/2; y: height/2
                 source: "/triangle_red.png"
             }
      
             Text {
                 y: 50
                 width: root.width
                 color: "white"
                 horizontalAlignment: Text.AlignHCenter
                 text: "Triangle"
             }
         }
      }
      

      The output is shown for Desktop. For other kits I just pressed the build button because I just needed the APK files.

      My questions:

      1- Is the type of the project exactly the one the book has used?
      2-Do I need to keep the Window section? If so why it's not shown in the example?
      3- Shouldn't I change anything in main.cpp?
      4- I built the project using the Arm Android kit but the size of the APK files for both Release and Debug modes are the same. I expected to have a smaller size for the Release mode. :(

      thank you.

      Arvindhan PonnusamyA Offline
      Arvindhan PonnusamyA Offline
      Arvindhan Ponnusamy
      wrote on last edited by
      #2

      @tomy If using engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      Window is must.
      If using QtQuickView to load the qml then can use Item/Components directly.

      tomyT 1 Reply Last reply
      2
      • tomyT tomy

        Hi,
        Using this example I first created an "Application > Qt Quick application project".
        I didn't change the main.cpp (and it was strange and interesting that even QML is also based on C++! Well done C++!)
        Then kept the Window part and entered the Rectangle section below that as follows:

        import QtQuick 2.6
        import QtQuick.Window 2.2
        
        Window {
            visible: true
            width: 640
            height: 480
            title: qsTr("Rec")
        
           Rectangle {
              id: root
              x: 50; y: 10
               width: 120; height: 240
               color: "Blue"
        
               Image {
                   id: triangle
                   x: root.width + width/2; y: height/2
                   source: "/triangle_red.png"
               }
        
               Text {
                   y: 50
                   width: root.width
                   color: "white"
                   horizontalAlignment: Text.AlignHCenter
                   text: "Triangle"
               }
           }
        }
        

        The output is shown for Desktop. For other kits I just pressed the build button because I just needed the APK files.

        My questions:

        1- Is the type of the project exactly the one the book has used?
        2-Do I need to keep the Window section? If so why it's not shown in the example?
        3- Shouldn't I change anything in main.cpp?
        4- I built the project using the Arm Android kit but the size of the APK files for both Release and Debug modes are the same. I expected to have a smaller size for the Release mode. :(

        thank you.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @tomy QML is not based on C++. It is a JavaScript dialect, but it can interact with C++.
        2. You can go without Window. Here is explained what this Window is: http://doc.qt.io/qt-5/qml-qtquick-window-window.html
        3. How does main look and does the app work?
        4. Release build should be smaller, indeed. You can inspect the content of both APKs to see what is in.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        tomyT 1 Reply Last reply
        4
        • jsulmJ jsulm

          @tomy QML is not based on C++. It is a JavaScript dialect, but it can interact with C++.
          2. You can go without Window. Here is explained what this Window is: http://doc.qt.io/qt-5/qml-qtquick-window-window.html
          3. How does main look and does the app work?
          4. Release build should be smaller, indeed. You can inspect the content of both APKs to see what is in.

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by
          #4

          @jsulm

          1. You can go without Window. Here is explained what this Window is: http://doc.qt.io/qt-5/qml-qtquick-window-window.html

          Thank you. How long! I will read it later.

          1. How does main look and does the app work?

          Here it's:

          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          
          int main(int argc, char *argv[])
          {
              QGuiApplication app(argc, argv);
          
              QQmlApplicationEngine engine;
              engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              if (engine.rootObjects().isEmpty())
                  return -1;
          
              return app.exec();
          }
          
          
          1. Release build should be smaller, indeed. You can inspect the content of both APKs to see what is in.

          How to inspect the contents of both APK files, please?

          jsulmJ 1 Reply Last reply
          0
          • tomyT tomy

            @jsulm

            1. You can go without Window. Here is explained what this Window is: http://doc.qt.io/qt-5/qml-qtquick-window-window.html

            Thank you. How long! I will read it later.

            1. How does main look and does the app work?

            Here it's:

            #include <QGuiApplication>
            #include <QQmlApplicationEngine>
            
            int main(int argc, char *argv[])
            {
                QGuiApplication app(argc, argv);
            
                QQmlApplicationEngine engine;
                engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                if (engine.rootObjects().isEmpty())
                    return -1;
            
                return app.exec();
            }
            
            
            1. Release build should be smaller, indeed. You can inspect the content of both APKs to see what is in.

            How to inspect the contents of both APK files, please?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @tomy "How long!" - well, if you really want to learn something you need to invest time, nothing is for free :-)
            Your main should be fine as long as you QML file is named main.qml and is in a resource file.
            APK files are just ZIP archives.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            tomyT 1 Reply Last reply
            1
            • Arvindhan PonnusamyA Arvindhan Ponnusamy

              @tomy If using engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              Window is must.
              If using QtQuickView to load the qml then can use Item/Components directly.

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #6

              @Arvindhan-Ponnusamy

              If using QtQuickView to load the qml then can use Item/Components directly.

              So how to use it please?

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @tomy "How long!" - well, if you really want to learn something you need to invest time, nothing is for free :-)
                Your main should be fine as long as you QML file is named main.qml and is in a resource file.
                APK files are just ZIP archives.

                tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by
                #7

                @jsulm

                Your main should be fine as long as you QML file is named main.qml and is in a resource file.

                Yes, they are as I posted the code above.

                APK files are just ZIP archives.

                Do you mean I open those files using a zip player like winRaR, please!?

                jsulmJ 1 Reply Last reply
                0
                • tomyT tomy

                  @jsulm

                  Your main should be fine as long as you QML file is named main.qml and is in a resource file.

                  Yes, they are as I posted the code above.

                  APK files are just ZIP archives.

                  Do you mean I open those files using a zip player like winRaR, please!?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @tomy said in A simple Qt Quick app:

                  Do you mean I open those files using a zip player like winRaR, please!?

                  yes

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by
                    #9

                    I opened both APK files using winRaR. They are identical regarding their items and sizes!

                    And about the example without a Window, I still don't know how to apply for that. you lead me to read Docs while a two-line of explanation would solve my issue, I think.

                    So far, I've referred to the Docs and can't remember even one time they have been useful for me. I'm 100% sure (judging by my own experience on them) that, Docs are not useful "for beginners", and you repeatedly refer us to there.

                    I don't like to read Docs and learn Qt/QML or anything using them. They just confuse me. I may some day refer to the Docs, when I'm no longer a novice on Qt.
                    for the time being I rely only on books instead. This is my desire.

                    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