Android qml imports
Solved
Announcements
-
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
-
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.
-
@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