[Qt-qml] Detecting platform in QML

Jonathan Zhong jonathan.zhong at panasonic.aero
Thu Jun 23 18:27:33 CEST 2011


Not sure if this is related. Sometimes I need to get values of system 
environment variables, so I have implemented a custom QML element called 
"System". In my C++ code:

class System : public QObject
{
     Q_OBJECT
//...
public:
     Q_INVOKABLE QString getenv(const QString envVarName) const; // 
Within this function I call the system getenv() function.
};

In my QML code:

import <My QML extension plugin> 1.0

System {
     id: system
}

// ...

var evValue = system.getenv("PWD");
console.log("...PWD = " + evValue);

The answer is "/home/jonathanz" on Linux, and "C:\users\jonathanz" on 
Windows, which may also indicate the platform I'm working on.

- jonathanz

On 06/23/2011 06:55 AM, Pelle Johnsen wrote:
> Guess I'll map it from C++, but would be good to have access to these 
> kind of system properties (and maybe also environment vars) from QML 
> in a later version.
>
>  -Pelle
>
> On Thu, Jun 23, 2011 at 1:10 PM, <jens.bache-wiig at nokia.com 
> <mailto:jens.bache-wiig at nokia.com>> wrote:
>
>     Not a silly question but I am afraid the answer is currently no.
>     The QML language itself doest not provide you this functionality
>     but it is possible to write a plugin in C++ that can provide it
>     for you.
>
>     Alternatively the Qt Quick desktop components provide a QStyleItem
>     that can give you the currently running desktop style as a
>     property. (as in "windows", "mac", "gtk", "oxygen")
>
>     http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/
>
>     Regards,
>     Jens Bache-Wiig
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110623/25523784/attachment.html 


More information about the Qt-qml mailing list