PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How to determine the platform Qt is running on at runtime?

 September 12, 2022     cross-platform, qt, qt4     No comments   

Issue

Is there a (Qt) way to determine the platform a Qt application is running on at runtime?


Solution

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.

If you are using a Qt version 5.9 or above, kindly use the below mentioned library function to retrieve correct OS details, more on this can be found here. There is also a QSysInfo class which can do some additional functionalities.

#ifdef Q_WS_WIN
#include <QOperatingSystemVersion>

switch(QOperatingSystemVersion::current())
{
  case QOperatingSystemVersion::Windows7: return "Windows 7";
  case QOperatingSystemVersion::Windows8: return "Windows 8";
  case QOperatingSystemVersion::Windows10: return "Windows 10";
  default: return "Windows";
}
#endif


Answered By - Reed Hedges
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing