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
Forum Updated to NodeBB v4.3 + New Features

Android qml imports

Scheduled Pinned Locked Moved Solved Announcements
androidqmlmacrosvirtualkeyboard
5 Posts 4 Posters 1.4k 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.
  • L Offline
    L Offline
    lopeztel
    wrote on 1 Jul 2020, 19:04 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
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 2 Jul 2020, 05:55 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(:^

      L 1 Reply Last reply 3 Jul 2020, 18:20
      3
      • J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 2 Jul 2020, 06:01 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
        • S sierdzio
          2 Jul 2020, 05:55

          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.

          L Offline
          L Offline
          lopeztel
          wrote on 3 Jul 2020, 18:20 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 8 Sept 2020, 05:14 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