Important: Please read the Qt Code of Conduct -

Platform dependent QML necessary ?

  • Hi all,

    we have a QML application that currently runs on a windows desktop system without any problems. Due to some internal restrictions we are using the MSAA framework for automated intergration testing and we trigger the UI via the Accessible properties and everything works fine, even the automated tests.
    Now we want to deploy it on a Windows CE device and the QT framework for this device is compiled with the QT_NO_ACCESSIBILITY define which is necessary to build QT for CE at all. This basically means we don't have the Accessible properties available here and the application cannot start due to unknown properties.

    So is there any way to reuse our QML-Files, or du we really have to maintain two different QML files? One for the Desktop system and one for the Windows CE system? Is there anything we can do like writing a wrapper attached property or something like an #ifdef in QML

    Thank you very much

  • You can try something like this
    DeviceManager class controls de plataform in compile time and with the property os you can obtain the platform over your app is running
    I only probe this in windows, linux and android, but i think it would help you

    //********** devicemanager.h *************


    #include <QObject>

    class DeviceManager : public QObject {

    Q_PROPERTY(DeviceManager::Plataform os READ os NOTIFY osChanged)    //This notify it really dont use

    enum Plataform {
    Windows, WindowsCE, Linux, Android, IOS, BlackBerry

    static DeviceManager* getInstance();
    Q_INVOKABLE DeviceManager::Plataform os();

    void osChanged();


    Plataform m_os;


    #endif // DEVICEMANAGER_H

    //************* devicemanager.cpp **************

    #include "devicemanager.h"

    DeviceManager* DeviceManager::getInstance()
    static DeviceManager* instance = NULL;
    if(instance == NULL)
    instance = new DeviceManager();
    return instance;

    DeviceManager::DeviceManager() : QObject()
    #if defined (Q_OS_ANDROID)
    m_os = Android;
    #elif defined (Q_OS_IOS)
    m_os = IOS;
    #elif defined (Q_OS_WINCE)
    m_os = WindowsCE;
    #elif defined (Q_OS_BLACKBERRY)
    m_os = BlackBerry;
    #elif defined (Q_OS_WIN)
    m_os = Windows;
    #elif defined (Q_OS_LINUX)
    m_os = Linux;

    DeviceManager::Plataform DeviceManager::os()
    return m_os;

    //************** main.cpp *******************

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>

    #include "devicemanager.h"

    int main(int argc, char *argv[])
    QGuiApplication app(argc, argv);

    qmlRegisterUncreatableType<DeviceManager>("mypackage", 1, 0, "Plataform", "Can't register DeviceManager::Plataform");
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("DeviceManagerObj", DeviceManager::getInstance());
    return app.exec();


    //***************** your_qml_file.qml ******************

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0

    import mypackage 1.0

    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Label {
        anchors.centerIn: parent
        text: {
            if(DeviceManagerObj.os == Plataform.Linux)
                return "Linux"
            else if(DeviceManagerObj.os == Plataform.WindowsCE)
                return "WindowsCE"
                return "Other OS"


Log in to reply