7#include <QtCore/qbytearray.h>
8#include <QtCore/qoperatingsystemversion.h>
9#include <QtCore/qstring.h>
11#include <private/qoperatingsystemversion_p.h>
14# include <sys/utsname.h>
15# include <private/qcore_unix_p.h>
19#include <QtCore/private/qjnihelpers_p.h>
23#if defined(Q_OS_SOLARIS)
24# include <sys/systeminfo.h>
27#if defined(Q_OS_DARWIN)
29# include <private/qcore_mac_p.h>
30# if __has_include(<IOKit/IOKitLib.h>)
31# include <IOKit/IOKitLib.h>
36# include <sys/sysctl.h>
39#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
41# include "private/qwinregistry_p.h"
89#if defined(Q_OS_DARWIN)
94 if (version.majorVersion() == 13)
96 if (version.majorVersion() == 12)
101 if (version.majorVersion() == 10) {
102 switch (version.minorVersion()) {
112 return "High Sierra";
126#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
128# ifndef QT_BOOTSTRAPPED
129class QWindowsSockInit
137QWindowsSockInit::QWindowsSockInit()
144 if (WSAStartup(MAKEWORD(2, 0), &wsadata) != 0) {
145 qWarning(
"QTcpSocketAPI: WinSock v2.0 initialization failed.");
151QWindowsSockInit::~QWindowsSockInit()
158static QString readVersionRegistryString(
const wchar_t *subKey)
160 return QWinRegistryKey(HKEY_LOCAL_MACHINE, LR
"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)")
164static inline QString windowsDisplayVersion()
169 return readVersionRegistryString(L
"DisplayVersion");
171 return readVersionRegistryString(L
"ReleaseId");
177 const qint16 major = osv.wServicePackMajor;
180 const qint16 minor = osv.wServicePackMinor;
193 const bool workstation = osver.wProductType == VER_NT_WORKSTATION;
195#define Q_WINVER(major, minor) (major << 8 | minor)
196 switch (Q_WINVER(osver.dwMajorVersion, osver.dwMinorVersion)) {
197 case Q_WINVER(10, 0):
199 if (osver.dwBuildNumber >= 22000)
204 if (osver.dwBuildNumber >= 20348)
205 return "Server 2022";
206 if (osver.dwBuildNumber >= 17763)
207 return "Server 2019";
208 return "Server 2016";
216#if defined(Q_OS_UNIX)
217# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD)
218# define USE_ETC_OS_RELEASE
242static QByteArray getEtcFileContent(
const char *filename)
250 if (QT_FSTAT(
fd, &sbuf) == -1) {
261static bool readEtcFile(QUnixOSVersion &
v,
const char *filename,
275 eol =
static_cast<const char *
>(memchr(
ptr,
'\n',
end -
ptr));
302static bool readOsRelease(QUnixOSVersion &
v)
313 return readEtcFile(
v,
"/etc/os-release",
id, versionId, prettyName) ||
314 readEtcFile(
v,
"/usr/lib/os-release",
id, versionId, prettyName);
317static bool readEtcLsbRelease(QUnixOSVersion &
v)
321 if (
ok && (
v.prettyName.isEmpty() ||
v.prettyName ==
v.productType)) {
330 if (QT_FSTAT(
fd, &sbuf) != -1 && sbuf.st_size >
v.prettyName.size()) {
344 return ok && !(
v.productType.isEmpty() &&
v.productVersion.isEmpty());
347#if defined(Q_OS_LINUX)
358static bool readEtcRedHatRelease(QUnixOSVersion &
v)
369 const char keyword[] =
"release ";
374 spaceIndex > -1 ? spaceIndex - releaseIndex -
int(strlen(keyword)) : -1));
378static bool readEtcDebianVersion(QUnixOSVersion &
v)
393static bool findUnixOsVersion(QUnixOSVersion &
v)
395 if (readOsRelease(
v))
397 if (readEtcLsbRelease(
v))
399#if defined(Q_OS_LINUX)
400 if (readEtcRedHatRelease(
v))
402 if (readEtcDebianVersion(
v))
429 return "Gingerbread";
436 return "Ice Cream Sandwich";
448 return "Marshmallow";
549 GetNativeSystemInfo(&
info);
550 switch (
info.wProcessorArchitecture) {
551# ifdef PROCESSOR_ARCHITECTURE_AMD64
552 case PROCESSOR_ARCHITECTURE_AMD64:
555# ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
556 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
558 case PROCESSOR_ARCHITECTURE_IA64:
561#elif defined(Q_OS_DARWIN) && !defined(Q_OS_MACOS)
564#elif defined(Q_OS_UNIX)
568# if defined(Q_OS_SOLARIS)
575 ret = sysinfo(SI_ARCHITECTURE_64, u.machine,
sizeof u.machine);
585# if defined(Q_PROCESSOR_ARM) || defined(QT_BUILD_INTERNAL)
586 if (strcmp(u.machine,
"aarch64") == 0)
588 if (strncmp(u.machine,
"armv", 4) == 0)
591# if defined(Q_PROCESSOR_POWER) || defined(QT_BUILD_INTERNAL)
593 if (strncmp(u.machine,
"ppc", 3) == 0)
595 if (strncmp(u.machine,
"powerpc", 7) == 0)
597 if (strcmp(u.machine,
"Power Macintosh") == 0)
600# if defined(Q_PROCESSOR_SPARC) || defined(QT_BUILD_INTERNAL)
603 if (strcmp(u.machine,
"sun4u") == 0 || strcmp(u.machine,
"sparc64") == 0)
605 if (strcmp(u.machine,
"sparc32") == 0)
608# if defined(Q_PROCESSOR_X86) || defined(QT_BUILD_INTERNAL)
610 if (strlen(u.machine) == 4 && u.machine[0] ==
'i'
611 && u.machine[2] ==
'8' && u.machine[3] ==
'6')
613 if (strcmp(u.machine,
"amd64") == 0)
697#elif defined(Q_OS_UNIX)
723 osver.majorVersion(), osver.minorVersion(), osver.microVersion());
774#elif defined(Q_OS_QNX)
777#elif defined(Q_OS_ANDROID)
780#elif defined(Q_OS_IOS)
782#elif defined(Q_OS_TVOS)
784#elif defined(Q_OS_WATCHOS)
786#elif defined(Q_OS_MACOS)
788#elif defined(Q_OS_DARWIN)
790#elif defined(Q_OS_WASM)
793#elif defined(USE_ETC_OS_RELEASE)
794 QUnixOSVersion unixOsVersion;
795 findUnixOsVersion(unixOsVersion);
796 if (!unixOsVersion.productType.isEmpty())
797 return unixOsVersion.productType;
838#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)
840 return QString::asprintf(
"%d.%d", version.majorVersion(), version.minorVersion());
841#elif defined(Q_OS_WIN)
842 const char *version = osVer_helper();
849#elif defined(USE_ETC_OS_RELEASE)
850 QUnixOSVersion unixOsVersion;
851 findUnixOsVersion(unixOsVersion);
852 if (!unixOsVersion.productVersion.isEmpty())
853 return unixOsVersion.productVersion;
876#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN) || defined(Q_OS_WIN)
878 const int majorVersion = version.majorVersion();
881 const char *
name = osVer_helper(version);
883 return result + versionString;
885# if !defined(Q_OS_WIN)
886 return result +
" ("_L1 + versionString + u
')';
889 const auto displayVersion = windowsDisplayVersion();
890 if (!displayVersion.isEmpty())
891 result +=
" Version "_L1 + displayVersion;
894#elif defined(Q_OS_HAIKU)
896#elif defined(Q_OS_UNIX)
897# ifdef USE_ETC_OS_RELEASE
898 QUnixOSVersion unixOsVersion;
899 findUnixOsVersion(unixOsVersion);
900 if (!unixOsVersion.prettyName.isEmpty())
901 return unixOsVersion.prettyName;
910#ifndef QT_BOOTSTRAPPED
929#if defined(Q_OS_LINUX)
942 unsigned long len = hostName.
size();
943 BOOL
res = GetComputerNameEx(ComputerNameDnsHostname,
944 reinterpret_cast<wchar_t *
>(
const_cast<quint16 *
>(hostName.
utf16())), &
len);
947 GetComputerNameEx(ComputerNameDnsHostname,
948 reinterpret_cast<wchar_t *
>(
const_cast<quint16 *
>(hostName.
utf16())), &
len);
955 if (gethostname(hostName,
sizeof(hostName)) == -1)
957 hostName[
sizeof(hostName) - 1] =
'\0';
965 UuidStringLen =
sizeof(
"00000000-0000-0000-0000-000000000000") - 1
992#if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>)
994 static const mach_port_t defaultPort = 0;
995 io_service_t service = IOServiceGetMatchingService(defaultPort, IOServiceMatching(
"IOPlatformExpertDevice"));
996 QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
997 CFStringGetCString(stringRef, uuid,
sizeof(uuid), kCFStringEncodingMacRoman);
999#elif defined(Q_OS_BSD4) && defined(KERN_HOSTUUID)
1001 size_t uuidlen =
sizeof(uuid);
1002 int name[] = { CTL_KERN, KERN_HOSTUUID };
1003 if (sysctl(
name,
sizeof name /
sizeof name[0], &uuid, &uuidlen,
nullptr, 0) == 0
1004 && uuidlen ==
sizeof(uuid))
1006#elif defined(Q_OS_UNIX)
1010 static const char fullfilename[] =
"/usr/local/var/lib/dbus/machine-id";
1011 const char *firstfilename = fullfilename +
sizeof(
"/usr/local") - 1;
1013 if (
fd == -1 && errno == ENOENT)
1024#elif defined(Q_OS_WIN)
1051 int fd =
qt_safe_open(
"/proc/sys/kernel/random/boot_id", O_RDONLY);
1059#elif defined(Q_OS_DARWIN)
1062 size_t uuidlen =
sizeof(uuid);
1063 if (sysctlbyname(
"kern.bootsessionuuid", uuid, &uuidlen,
nullptr, 0) == 0
1064 && uuidlen ==
sizeof(uuid))
QByteArray trimmed() const &
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
QByteArray toLower() const &
static QOperatingSystemVersion current()
[0]
static constexpr QOperatingSystemVersionBase Windows10_20H2
\variable QOperatingSystemVersion::Windows10_20H2
static constexpr QOperatingSystemVersionBase MacOSBigSur
\variable QOperatingSystemVersion::MacOSBigSur
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void truncate(qsizetype pos)
Truncates the string at the given position index.
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString toLower() const &
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString & setRawData(const QChar *unicode, qsizetype size)
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
void resize(qsizetype size)
Sets the size of the string to size characters.
static QString currentCpuArchitecture()
static QByteArray bootUniqueId()
static QString buildAbi()
static QByteArray machineUniqueId()
static QString kernelVersion()
static QString machineHostName()
static QString productType()
static QString kernelType()
static QString buildCpuArchitecture()
static QString productVersion()
static QString prettyProductName()
QString stringValue(QStringView subKey) const
Combined button and popup list for selecting options.
Q_CORE_EXPORT jint androidSdkVersion()
constexpr Initialization Uninitialized
#define QByteArrayLiteral(str)
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_close(int fd)
static QString unquote(QStringView str)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static ControlElement< T > * ptr(QWidget *widget)
GLsizei const GLfloat * v
[13]
OSVERSIONINFOEX qWindowsVersionInfo()
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QStringLiteral(str)
static QString unknownText()
if(qFloatDistance(a, b)<(1<< 7))
[0]
QFileInfo info(fileName)
[8]
\inmodule QtCore \reentrant