Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Announcements
  4. Android qml imports
Qt 6.11 is out! See what's new in the release blog

Android qml imports

Scheduled Pinned Locked Moved Solved Announcements
androidqmlmacrosvirtualkeyboard
5 Posts 4 Posters 2.0k Views 2 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.
  • lopeztelL Offline
    lopeztelL Offline
    lopeztel
    wrote on last edited by
    #1

    I have the following in my main.qml file :

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    import QtQuick.VirtualKeyboard 2.4 //comment for Android
    import MqttClient 1.0
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.1
    import QtCharts 2.3
    import QtQuick.Controls.Material 2.3
    

    And I know it is possible to use macros for the C++ code, is it possible to do something like this?

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    #ifdef Q_OS_ANDROID
    import QtQuick.VirtualKeyboard 2.4 //comment for Android
    #endif
    import MqttClient 1.0
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.1
    import QtCharts 2.3
    import QtQuick.Controls.Material 2.3
    

    My solution so far is deleting this part of the code every time I build but something tells me there must be a more elegant solution

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      There are no ifdefs and no preprocessor in QML. You can create 2 versions of this file and load them based on platform - you can use QFileSelector for that, there is a built-in support for this in QML: see the docs.

      (Z(:^

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

        Additionale to what @sierdzio said, I always suggest moving the platform specific part into its own file and load it via a loader and only set the loader to active when Qt.platform.os !== "android"


        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.

        1 Reply Last reply
        2
        • sierdzioS sierdzio

          There are no ifdefs and no preprocessor in QML. You can create 2 versions of this file and load them based on platform - you can use QFileSelector for that, there is a built-in support for this in QML: see the docs.

          lopeztelL Offline
          lopeztelL Offline
          lopeztel
          wrote on last edited by
          #4

          @sierdzio Thanks, this is exactly what I needed! Ended up doing:

          #if defined(Q_OS_ANDROID)
              const QUrl url(QStringLiteral("qrc:/main_android.qml"));
              #elif defined (Q_OS_LINUX)
              const QUrl url(QStringLiteral("qrc:/main_linux.qml"));
              #endif
          

          in my main.cpp

          1 Reply Last reply
          1
          • K Offline
            K Offline
            keny
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            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