Thursday, September 28, 2017

QOperatingSystemVersion - new class in Qt 5.9

Qt 5.9 is a current LTS release from Qt Company. In Qt Core we see a new class QOperationSystemVersion which aim is to replace some of the methods of QSysInfo class.

Let's see how this new class works. First create Qt console application and include necessary header:

#include <QOperatingSystemVersion>

After including the header we can use methods of QOperationSystemVersion class for getting information about our system. Available information includes system name, major version, minor version, micro version. Also it includes operation version in form of OSType enumeration which can be convenient if you need to execute some specific code, for example, for Mac OS or Windows.

auto osversion = QOperatingSystemVersion::current();

std::cout << << std::endl;
std::cout << osversion.majorVersion() << "." << osversion.minorVersion()
          << "." << osversion.microVersion() << std::endl;

if (osversion.type() == QOperatingSystemVersion::Windows)
    std::cout << "Hi, we are on Windows!" << std::endl;

This code executed, for instance, on Windows 8.1 gives the following output:

Hi, we are on Windows!

No comments:

Post a Comment