Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. application runs in C++ or in the original system language
Forum Updated to NodeBB v4.3 + New Features

application runs in C++ or in the original system language

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 3 Posters 1.3k 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.
  • C Offline
    C Offline
    Clovr
    wrote on last edited by
    #1

    I have a question: When I create a phone application using Qt, the application runs in C++ or in the original system language

    jsulmJ 1 Reply Last reply
    0
    • C Clovr

      I have a question: When I create a phone application using Qt, the application runs in C++ or in the original system language

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

      @Clovr Qt is a C++ framework. But there are language bindings for some other languages like Python. Not sure about Java/Kotlin or Swift though. At least for Android you can write applications in C++, so Qt can be used there (Android is an officially supported platform).

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

      C 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Clovr Qt is a C++ framework. But there are language bindings for some other languages like Python. Not sure about Java/Kotlin or Swift though. At least for Android you can write applications in C++, so Qt can be used there (Android is an officially supported platform).

        C Offline
        C Offline
        Clovr
        wrote on last edited by
        #3

        @jsulm I mean, does Qt convert code written in C++ into the native language of the target system?

        jsulmJ J.HilkJ 2 Replies Last reply
        0
        • C Clovr

          @jsulm I mean, does Qt convert code written in C++ into the native language of the target system?

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

          @Clovr said in application runs in C++ or in the original system language:

          does Qt convert code written in C++ into the native language of the target system?

          No
          Qt is just a framework, it does not convert anything.

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

          C 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Clovr said in application runs in C++ or in the original system language:

            does Qt convert code written in C++ into the native language of the target system?

            No
            Qt is just a framework, it does not convert anything.

            C Offline
            C Offline
            Clovr
            wrote on last edited by
            #5

            @jsulm I mean, when I create a phone application in C++ using Qt, when I build the application and run it on the Android system, does the application run as fast as C++ or java/kotlin? Thank you for the response.

            jsulmJ 1 Reply Last reply
            0
            • C Clovr

              @jsulm I mean, does Qt convert code written in C++ into the native language of the target system?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Clovr usually the qt code is compiled to a library that then is loaded from native code. That's how it's done for Android for example.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              C 1 Reply Last reply
              1
              • C Clovr

                @jsulm I mean, when I create a phone application in C++ using Qt, when I build the application and run it on the Android system, does the application run as fast as C++ or java/kotlin? Thank you for the response.

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

                @Clovr said in application runs in C++ or in the original system language:

                when I build the application and run it on the Android system, does the application run as fast as C++

                On Android Qt applications are build as native applications - machine code not Java byte code (that's why you need NDK to get C++ compiler), so they run as fast as any other application written in C++. iOS apps are anyway native as far as I know (no byte code and virtual machines involved).

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

                1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Clovr usually the qt code is compiled to a library that then is loaded from native code. That's how it's done for Android for example.

                  C Offline
                  C Offline
                  Clovr
                  wrote on last edited by
                  #8

                  @J-Hilk Please explain in detail Thank you for the response

                  J.HilkJ 1 Reply Last reply
                  0
                  • C Clovr

                    @J-Hilk Please explain in detail Thank you for the response

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @Clovr the audacity!
                    Here's a chatgpt answer best I can do this early during technically my work time:

                    To understand the inner workings of how a Qt-based application is generated, loaded, and launched on an Android device, it's important to dive into the compilation process, the generation of the APK (Android Package), and the execution flow on the device. Here’s a detailed explanation:

                    1. Compilation and Packaging

                    a. Qt Project Compilation

                    1. Qt Application Code: The application code, written in C++ and optionally QML, is compiled using the Android NDK. Qt provides a set of tools and build configurations to cross-compile the application for the ARM architecture used by most Android devices.

                    2. Shared Libraries: The result of the compilation process includes shared libraries (e.g., libMyApp.so) which contain the compiled C++ code. These libraries are compiled with references to the Qt libraries (e.g., libQt5Core.so, libQt5Gui.so, etc.).

                    3. QML Files: If the application uses QML for its UI, these files are either embedded into the binary using Qt resource files (.qrc) or packaged alongside the application.

                    b. Java Native Interface (JNI)

                    1. JNI Bridge: The Qt framework uses JNI to bridge the gap between Java (the primary language for Android applications) and C++ (used by Qt). JNI functions are generated and compiled into the native libraries.

                    2. Java Loader: Qt provides a Java loader class that is responsible for loading the native libraries and initiating the Qt application. This loader is typically named org.qtproject.qt5.android.bindings.QtActivity.

                    c. APK Generation

                    1. AndroidManifest.xml: This manifest file defines the essential information about the application, such as the Java entry point, required permissions, and hardware features.

                    2. Gradle Build System: Qt integrates with the Android Gradle build system to package the compiled shared libraries, Java classes, resources, and the manifest into an APK.

                    3. Packaging: The final APK includes:

                      • The compiled Java classes (.class files converted to .dex format).
                      • The compiled native libraries (.so files).
                      • Resource files (QML, images, etc.).
                      • The AndroidManifest.xml file.

                    2. Application Loading and Launching

                    a. Application Installation

                    1. Installation: When the APK is installed on an Android device, the system extracts and places the components in the appropriate directories (e.g., lib/armeabi-v7a/ for the shared libraries).

                    b. Loading the Qt Environment

                    1. Java Entry Point: When the user launches the application, the Android system calls the onCreate method of the main activity specified in the AndroidManifest.xml. For a Qt application, this is typically org.qtproject.qt5.android.bindings.QtActivity.

                    2. Loading Native Libraries:

                      • The Java loader class (QtActivity) calls System.loadLibrary("MyApp") to load the main application library.
                      • This, in turn, loads the necessary Qt libraries.
                    3. JNI Initialization: During the loading of the native library, the JNI initialization functions are called. These functions set up the environment for the Qt application.

                    c. Starting the Qt Application

                    1. Qt Application Context:

                      • The QtActivity initializes the Qt application context. This involves setting up the Qt event loop, loading QML files if used, and initializing any necessary Qt modules (like QtCore, QtGui, etc.).
                    2. Event Loop: The Qt event loop is started. This loop is responsible for handling user input, screen rendering, and other event-driven tasks typical in a GUI application.

                    3. QML Engine: If the application uses QML, the QQmlApplicationEngine is instantiated, and the main QML file is loaded. This file defines the user interface and its interaction logic.

                    d. Interaction with Android Components

                    1. JNI Calls: Throughout the application lifecycle, the Java and C++ layers communicate via JNI. For instance, when the application needs to access Android-specific features (like sensors, camera, etc.), it makes JNI calls to interact with Java APIs.

                    2. Android Activity Lifecycle: The QtActivity class manages the interaction between the Android activity lifecycle (onPause, onResume, etc.) and the Qt application lifecycle, ensuring that Qt state is preserved appropriately during activity transitions.

                    Summary of Execution Flow

                    1. Compilation:

                      • C++ and QML code is compiled into shared libraries and resources.
                      • JNI functions and Java loader classes are compiled.
                    2. Packaging:

                      • The APK is generated, containing all necessary binaries, resources, and manifest.
                    3. Installation:

                      • The APK is installed on the device, placing files in the appropriate directories.
                    4. Launch:

                      • The user launches the application, invoking the QtActivity.
                      • Native libraries are loaded via JNI.
                      • Qt environment is initialized, and the event loop starts.
                      • The main QML file is loaded (if applicable).
                    5. Runtime:

                      • The application interacts with Android components via JNI.
                      • The Qt event loop handles user interaction and rendering.

                    By understanding these steps, you can appreciate the complexity and the seamless integration that allows a Qt-based application to run on an Android device, leveraging both the power of the Qt framework and the native capabilities of the Android platform.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    C 1 Reply Last reply
                    1
                    • J.HilkJ J.Hilk

                      @Clovr the audacity!
                      Here's a chatgpt answer best I can do this early during technically my work time:

                      To understand the inner workings of how a Qt-based application is generated, loaded, and launched on an Android device, it's important to dive into the compilation process, the generation of the APK (Android Package), and the execution flow on the device. Here’s a detailed explanation:

                      1. Compilation and Packaging

                      a. Qt Project Compilation

                      1. Qt Application Code: The application code, written in C++ and optionally QML, is compiled using the Android NDK. Qt provides a set of tools and build configurations to cross-compile the application for the ARM architecture used by most Android devices.

                      2. Shared Libraries: The result of the compilation process includes shared libraries (e.g., libMyApp.so) which contain the compiled C++ code. These libraries are compiled with references to the Qt libraries (e.g., libQt5Core.so, libQt5Gui.so, etc.).

                      3. QML Files: If the application uses QML for its UI, these files are either embedded into the binary using Qt resource files (.qrc) or packaged alongside the application.

                      b. Java Native Interface (JNI)

                      1. JNI Bridge: The Qt framework uses JNI to bridge the gap between Java (the primary language for Android applications) and C++ (used by Qt). JNI functions are generated and compiled into the native libraries.

                      2. Java Loader: Qt provides a Java loader class that is responsible for loading the native libraries and initiating the Qt application. This loader is typically named org.qtproject.qt5.android.bindings.QtActivity.

                      c. APK Generation

                      1. AndroidManifest.xml: This manifest file defines the essential information about the application, such as the Java entry point, required permissions, and hardware features.

                      2. Gradle Build System: Qt integrates with the Android Gradle build system to package the compiled shared libraries, Java classes, resources, and the manifest into an APK.

                      3. Packaging: The final APK includes:

                        • The compiled Java classes (.class files converted to .dex format).
                        • The compiled native libraries (.so files).
                        • Resource files (QML, images, etc.).
                        • The AndroidManifest.xml file.

                      2. Application Loading and Launching

                      a. Application Installation

                      1. Installation: When the APK is installed on an Android device, the system extracts and places the components in the appropriate directories (e.g., lib/armeabi-v7a/ for the shared libraries).

                      b. Loading the Qt Environment

                      1. Java Entry Point: When the user launches the application, the Android system calls the onCreate method of the main activity specified in the AndroidManifest.xml. For a Qt application, this is typically org.qtproject.qt5.android.bindings.QtActivity.

                      2. Loading Native Libraries:

                        • The Java loader class (QtActivity) calls System.loadLibrary("MyApp") to load the main application library.
                        • This, in turn, loads the necessary Qt libraries.
                      3. JNI Initialization: During the loading of the native library, the JNI initialization functions are called. These functions set up the environment for the Qt application.

                      c. Starting the Qt Application

                      1. Qt Application Context:

                        • The QtActivity initializes the Qt application context. This involves setting up the Qt event loop, loading QML files if used, and initializing any necessary Qt modules (like QtCore, QtGui, etc.).
                      2. Event Loop: The Qt event loop is started. This loop is responsible for handling user input, screen rendering, and other event-driven tasks typical in a GUI application.

                      3. QML Engine: If the application uses QML, the QQmlApplicationEngine is instantiated, and the main QML file is loaded. This file defines the user interface and its interaction logic.

                      d. Interaction with Android Components

                      1. JNI Calls: Throughout the application lifecycle, the Java and C++ layers communicate via JNI. For instance, when the application needs to access Android-specific features (like sensors, camera, etc.), it makes JNI calls to interact with Java APIs.

                      2. Android Activity Lifecycle: The QtActivity class manages the interaction between the Android activity lifecycle (onPause, onResume, etc.) and the Qt application lifecycle, ensuring that Qt state is preserved appropriately during activity transitions.

                      Summary of Execution Flow

                      1. Compilation:

                        • C++ and QML code is compiled into shared libraries and resources.
                        • JNI functions and Java loader classes are compiled.
                      2. Packaging:

                        • The APK is generated, containing all necessary binaries, resources, and manifest.
                      3. Installation:

                        • The APK is installed on the device, placing files in the appropriate directories.
                      4. Launch:

                        • The user launches the application, invoking the QtActivity.
                        • Native libraries are loaded via JNI.
                        • Qt environment is initialized, and the event loop starts.
                        • The main QML file is loaded (if applicable).
                      5. Runtime:

                        • The application interacts with Android components via JNI.
                        • The Qt event loop handles user interaction and rendering.

                      By understanding these steps, you can appreciate the complexity and the seamless integration that allows a Qt-based application to run on an Android device, leveraging both the power of the Qt framework and the native capabilities of the Android platform.

                      C Offline
                      C Offline
                      Clovr
                      wrote on last edited by
                      #10

                      @J-Hilk Does this mean that mobile applications made in C++ using Qt run at the same speed as C++?

                      1 Reply Last reply
                      0
                      • J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #11

                        Mobile applications made in C++ using Qt generally run at a speed comparable to native C++ applications. Here are several reasons why:

                        1. Native Code Execution

                        When you develop a Qt application for Android, your C++ code is compiled into native ARM (or x86 for some devices) machine code using the Android NDK. This means the execution of your C++ code is as fast as any other native application because it runs directly on the CPU without an additional layer of interpretation or runtime overhead.

                        2. Efficient Rendering

                        Qt uses efficient rendering techniques. For instance:

                        • Qt Quick: When using QML and Qt Quick, the rendering is handled by a high-performance scene graph and OpenGL (or Vulkan on some devices) for rendering the UI, which is hardware-accelerated.
                        • Qt Widgets: If you are using traditional Qt Widgets, the rendering is also highly optimized and leverages native graphics APIs.

                        3. Performance Optimizations

                        Qt provides several performance optimizations:

                        • Multithreading: Qt supports multithreading and concurrent programming, allowing developers to offload heavy tasks to separate threads, keeping the UI responsive.
                        • Memory Management: Qt uses efficient memory management techniques and has support for various data structures that are optimized for performance.

                        4. JNI Overhead

                        The interaction between Java and C++ via JNI (Java Native Interface) does introduce some overhead. However, this overhead is generally minimal if the JNI calls are not excessively frequent or computationally intensive. Properly designed applications will minimize the performance impact by reducing the frequency and complexity of JNI interactions.

                        5. Framework Overhead

                        While Qt is a powerful and feature-rich framework, using it does introduce some overhead compared to writing raw C++ code because of its abstractions and additional features. However, this overhead is typically minimal compared to the benefits of using a high-level framework that simplifies development.

                        6. Optimizations for Mobile Platforms

                        Qt has been optimized for mobile platforms, including Android. This means:

                        • Reduced Memory Footprint: Qt's mobile modules are designed to be lightweight and efficient.
                        • Battery Efficiency: Qt applications are optimized to minimize battery consumption by leveraging efficient background processing and power management techniques.

                        Practical Considerations

                        • Development Speed vs. Runtime Speed: While Qt applications run close to native speed, one of the main advantages is the increased development speed and cross-platform capabilities. You write your code once and deploy it on multiple platforms with minimal changes.
                        • Profiling and Optimization: Like any application, profiling and optimization are key. Tools like Qt Creator's built-in profiler, Valgrind, and others can help identify and optimize performance bottlenecks.

                        Conclusion

                        In summary, Qt-based mobile applications run at a speed close to that of native C++ applications because the Qt framework compiles your C++ code into native machine code, leverages hardware acceleration for rendering, and uses efficient memory and performance management techniques. While there may be some minimal overhead due to framework abstractions and JNI interactions, the performance impact is generally negligible compared to the benefits of using a robust, cross-platform framework like Qt.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        C 1 Reply Last reply
                        0
                        • J.HilkJ J.Hilk

                          Mobile applications made in C++ using Qt generally run at a speed comparable to native C++ applications. Here are several reasons why:

                          1. Native Code Execution

                          When you develop a Qt application for Android, your C++ code is compiled into native ARM (or x86 for some devices) machine code using the Android NDK. This means the execution of your C++ code is as fast as any other native application because it runs directly on the CPU without an additional layer of interpretation or runtime overhead.

                          2. Efficient Rendering

                          Qt uses efficient rendering techniques. For instance:

                          • Qt Quick: When using QML and Qt Quick, the rendering is handled by a high-performance scene graph and OpenGL (or Vulkan on some devices) for rendering the UI, which is hardware-accelerated.
                          • Qt Widgets: If you are using traditional Qt Widgets, the rendering is also highly optimized and leverages native graphics APIs.

                          3. Performance Optimizations

                          Qt provides several performance optimizations:

                          • Multithreading: Qt supports multithreading and concurrent programming, allowing developers to offload heavy tasks to separate threads, keeping the UI responsive.
                          • Memory Management: Qt uses efficient memory management techniques and has support for various data structures that are optimized for performance.

                          4. JNI Overhead

                          The interaction between Java and C++ via JNI (Java Native Interface) does introduce some overhead. However, this overhead is generally minimal if the JNI calls are not excessively frequent or computationally intensive. Properly designed applications will minimize the performance impact by reducing the frequency and complexity of JNI interactions.

                          5. Framework Overhead

                          While Qt is a powerful and feature-rich framework, using it does introduce some overhead compared to writing raw C++ code because of its abstractions and additional features. However, this overhead is typically minimal compared to the benefits of using a high-level framework that simplifies development.

                          6. Optimizations for Mobile Platforms

                          Qt has been optimized for mobile platforms, including Android. This means:

                          • Reduced Memory Footprint: Qt's mobile modules are designed to be lightweight and efficient.
                          • Battery Efficiency: Qt applications are optimized to minimize battery consumption by leveraging efficient background processing and power management techniques.

                          Practical Considerations

                          • Development Speed vs. Runtime Speed: While Qt applications run close to native speed, one of the main advantages is the increased development speed and cross-platform capabilities. You write your code once and deploy it on multiple platforms with minimal changes.
                          • Profiling and Optimization: Like any application, profiling and optimization are key. Tools like Qt Creator's built-in profiler, Valgrind, and others can help identify and optimize performance bottlenecks.

                          Conclusion

                          In summary, Qt-based mobile applications run at a speed close to that of native C++ applications because the Qt framework compiles your C++ code into native machine code, leverages hardware acceleration for rendering, and uses efficient memory and performance management techniques. While there may be some minimal overhead due to framework abstractions and JNI interactions, the performance impact is generally negligible compared to the benefits of using a robust, cross-platform framework like Qt.

                          C Offline
                          C Offline
                          Clovr
                          wrote on last edited by
                          #12

                          @J-Hilk thank you so much

                          1 Reply Last reply
                          1

                          • Login

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