Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qoperatingsystemversion_darwin.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#import <Foundation/Foundation.h>
7
8#include <QtCore/qfile.h>
9#include <QtCore/qversionnumber.h>
10
11#if !defined(QT_BOOTSTRAPPED)
12#include <QtCore/qprocess.h>
13#endif
14
16
17using namespace Qt::StringLiterals;
18
19QOperatingSystemVersionBase QOperatingSystemVersionBase::current_impl()
20{
21 NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
22 QVersionNumber versionNumber(osv.majorVersion, osv.minorVersion, osv.patchVersion);
23
24 if (versionNumber.majorVersion() == 10 && versionNumber.minorVersion() >= 16) {
25 // The process is running in system version compatibility mode,
26 // due to the executable being built against a pre-macOS 11 SDK.
27 // This might happen even if we require a more recent SDK for
28 // building Qt applications, as the Qt 'app' might be a plugin
29 // hosted inside a host that used an earlier SDK. But, since we
30 // require a recent SDK for the Qt app itself, the application
31 // should be prepared for versions numbers beyond 10, and we can
32 // resolve the real version number here.
33#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(process)
34 QProcess sysctl;
35 QProcessEnvironment nonCompatEnvironment;
36 nonCompatEnvironment.insert("SYSTEM_VERSION_COMPAT"_L1, "0"_L1);
37 sysctl.setProcessEnvironment(nonCompatEnvironment);
38 sysctl.start("/usr/sbin/sysctl"_L1, QStringList() << "-b"_L1 << "kern.osproductversion"_L1);
39 if (sysctl.waitForFinished()) {
40 auto versionString = QString::fromLatin1(sysctl.readAll());
41 auto nonCompatSystemVersion = QVersionNumber::fromString(versionString);
42 if (!nonCompatSystemVersion.isNull())
43 versionNumber = nonCompatSystemVersion;
44 }
45#endif
46 }
47
48 QOperatingSystemVersionBase operatingSystemVersion;
49 operatingSystemVersion.m_os = currentType();
50 operatingSystemVersion.m_major = versionNumber.majorVersion();
51 operatingSystemVersion.m_minor = versionNumber.minorVersion();
52 operatingSystemVersion.m_micro = versionNumber.microVersion();
53
54 return operatingSystemVersion;
55}
56
static constexpr OSType currentType()
\inmodule QtCore
Definition qprocess.h:32
void insert(const QString &name, const QString &value)
Inserts the environment variable of name name and contents value into this QProcessEnvironment object...
Definition qprocess.cpp:285
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
\inmodule QtCore
static Q_CORE_EXPORT QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex=nullptr)
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.