Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Platform dependent QML necessary ?
Forum Updated to NodeBB v4.3 + New Features

Platform dependent QML necessary ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.0k 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.
  • T Offline
    T Offline
    Tobias F
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Camilo del RealC Offline
      Camilo del RealC Offline
      Camilo del Real
      wrote on last edited by
      #2

      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 *************

      #ifndef DEVICEMANAGER_H
      #define DEVICEMANAGER_H

      #include <QObject>

      class DeviceManager : public QObject {

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

      public:
      enum Plataform {
      Windows, WindowsCE, Linux, Android, IOS, BlackBerry
      };
      Q_ENUM(Plataform)

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

      signals:
      void osChanged();

      private:
      DeviceManager();

      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;
      #endif
      }

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

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

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

      #include "devicemanager.h"

      int main(int argc, char *argv[])
      {
      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      QGuiApplication app(argc, argv);

      qmlRegisterUncreatableType<DeviceManager>("mypackage", 1, 0, "Plataform", "Can't register DeviceManager::Plataform");
      
      QQmlApplicationEngine engine;
      engine.rootContext()->setContextProperty("DeviceManagerObj", DeviceManager::getInstance());
      engine.load(QUrl(QLatin1String("qrc:/main.qml")));
      
      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"
              else
                  return "Other OS"
          }
      }
      

      }

      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