Get the OS platform name in C++
Hey, I was wondering if it's possible to get the platform name from c++ like in QML with Qt.platform.os?
The class QQmlPlatform seems to be private sadly, of course I could just copy the code from the method but that is not considered good practice in my opinion...
another way would be to get the string from thr QML engine like this:
QString os = engine->evaluate("Qt.platform.os").toString();
that works and I have a pointer to the QQmlEngine anyways, but seems like a lot of hassle to run the actual C++ methode QQmlPlatform::os like this.. :D
Take a look on "QGuiApplication":http://qt-project.org/doc/qt-5/qguiapplication.html#platformName-prop
hey thanks, yeah I just found that myself, is that always the same string as the QML version? because the doc says nothing about mobile platforms, also it returns "Cocoa" for Mac OS X and not "osx" like QQmlPlatform::os() does, but I might use that instead..
In the widgets world the platform is defined during build configuration.
The qconfig.h file has a define QT_QPA_DEFAULT_PLATFORM_NAME that keeps the platform name.
And this name is used to create a platform specific plugin.
For MacOSX the plugin directory is
IMHO, if you need a unified solution then it is better to copy QQmlPlatform::os() to you project.