Hi all,
Is there a (Qt) way to determine the platform a Qt application is running on at runtime?
Hi all,
Is there a (Qt) way to determine the platform a Qt application is running on at runtime?
There are macro that are defined on the corresponding platforms:
For more informations there is the QSysInfo class.
You can write this function:
QString getSystem() {
#ifdef Q_WS_X11
return QString("Linux");
#endif
#ifdef Q_WS_MAC
return QString("Mac");
#endif
#ifdef Q_WS_QWS
return QString("Embedded Linux");
#endif
#ifdef Q_WS_WIN
return QString("Windows");
#endif
}
I think this is as dynamic as it gets, why would you want to have it more dynamic?
Some more informations can be found here: http://stackoverflow.com/questions/341594/how-do-i-read-system-information-in-c
Note that the Q_WS_* macros are defined at compile time, but QSysInfo gives some run time details.
To extend gs's function to get the specific windows version at runtime, you can do
#ifdef Q_WS_WIN
switch(QSysInfo::windowsVersion())
{
case QSysInfo::WV_2000: return "Windows 2000";
case QSysInfo::WV_XP: return "Windows XP";
case QSysInfo::WV_VISTA: return "Windows Vista";
default: return "Windows";
}
#endif
and similar for Mac.