summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp116
1 files changed, 84 insertions, 32 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index ae3e86629e..2d4edb48d1 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -39,6 +39,7 @@
#include "qthreadstorage.h"
#include "qdir.h"
#include "qdatetime.h"
+#include <private/qlocale_tools_p.h>
#ifndef QT_NO_QOBJECT
#include <private/qthread_p.h>
@@ -984,9 +985,9 @@ bool qSharedBuild() Q_DECL_NOTHROW
\li \l ByteOrder specifies whether the platform is big-endian or
little-endian.
\li \l WindowsVersion specifies the version of the Windows operating
- system on which the application is run (Windows only)
+ system on which the application is run.
\li \l MacintoshVersion specifies the version of the Macintosh
- operating system on which the application is run (Mac only).
+ operating system on which the application is run.
\endlist
Some constants are defined only on certain platforms. You can use
@@ -1009,7 +1010,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
/*!
\variable QSysInfo::WindowsVersion
\brief the version of the Windows operating system on which the
- application is run (Windows only)
+ application is run.
*/
/*!
@@ -1017,19 +1018,22 @@ bool qSharedBuild() Q_DECL_NOTHROW
\since 4.4
Returns the version of the Windows operating system on which the
- application is run (Windows only).
+ application is run, or WV_None if the operating system is not
+ Windows.
*/
/*!
\variable QSysInfo::MacintoshVersion
\brief the version of the Macintosh operating system on which
- the application is run (Mac only).
+ the application is run.
*/
/*!
\fn QSysInfo::MacVersion QSysInfo::macVersion()
- Returns the version of Darwin (OS X or iOS) on which the application is run.
+ Returns the version of Darwin (OS X or iOS) on which the
+ application is run, or MV_None if the operating system
+ is not a version of Darwin.
*/
/*!
@@ -1092,6 +1096,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value WV_NT_based NT-based version of Windows
\value WV_CE_based CE-based version of Windows
+ \value WV_None Operating system other than Windows.
+
\sa MacVersion
*/
@@ -1139,6 +1145,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value MV_IOS_7_1 iOS 7.1
\value MV_IOS_8_0 iOS 8.0
+ \value MV_None Not a Darwin operating system
+
\sa WinVersion
*/
@@ -1845,16 +1853,14 @@ Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
QSysInfo::MacVersion QSysInfo::macVersion()
{
+ const QAppleOperatingSystemVersion version = qt_apple_os_version(); // qtcore_mac_objc.mm
#if defined(Q_OS_OSX)
- SInt32 gestalt_version;
- if (Gestalt(gestaltSystemVersionMinor, &gestalt_version) == noErr) {
- // add 2 because OS X 10.0 is 0x02 in the enum
- return QSysInfo::MacVersion(gestalt_version + 2);
- }
+ return QSysInfo::MacVersion(Q_MV_OSX(version.major, version.minor));
#elif defined(Q_OS_IOS)
- return qt_ios_version(); // qtcore_mac_objc.mm
-#endif
+ return QSysInfo::MacVersion(Q_MV_IOS(version.major, version.minor));
+#else
return QSysInfo::MV_Unknown;
+#endif
}
const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion();
@@ -2493,25 +2499,9 @@ QString QSysInfo::productType()
*/
QString QSysInfo::productVersion()
{
-#if defined(Q_OS_IOS)
- int major = (int(MacintoshVersion) >> 4) & 0xf;
- int minor = int(MacintoshVersion) & 0xf;
- if (Q_LIKELY(major < 10 && minor < 10)) {
- char buf[4] = { char(major + '0'), '.', char(minor + '0'), '\0' };
- return QString::fromLatin1(buf, 3);
- }
- return QString::number(major) + QLatin1Char('.') + QString::number(minor);
-#elif defined(Q_OS_OSX)
- int minor = int(MacintoshVersion) - 2; // we're not running on Mac OS 9
- Q_ASSERT(minor < 100);
- char buf[] = "10.0\0";
- if (Q_LIKELY(minor < 10)) {
- buf[3] += minor;
- } else {
- buf[3] += minor / 10;
- buf[4] = '0' + minor % 10;
- }
- return QString::fromLatin1(buf);
+#if defined(Q_OS_MAC)
+ const QAppleOperatingSystemVersion version = qt_apple_os_version();
+ return QString::number(version.major) + QLatin1Char('.') + QString::number(version.minor);
#elif defined(Q_OS_WIN)
const char *version = winVer_helper();
if (version)
@@ -3007,6 +2997,53 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT
/*!
\relates <QtGlobal>
+ \since 5.5
+
+ Returns the numerical value of the environment variable \a varName.
+ If \a ok is not null, sets \c{*ok} to \c true or \c false depending
+ on the success of the conversion.
+
+ Equivalent to
+ \code
+ qgetenv(varName).toInt()
+ \endcode
+ except that it's much faster, and can't throw exceptions.
+
+ \sa qgetenv(), qEnvironmentVariableIsSet()
+*/
+int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+ // we provide a buffer that can hold any int value:
+ static const int NumBinaryDigitsPerOctalDigit = 3;
+ static const int MaxDigitsForOctalInt =
+ (std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit;
+ char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-'
+ size_t dummy;
+ if (getenv_s(&dummy, buffer, sizeof buffer, varName) != 0) {
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+#else
+ const char * const buffer = ::getenv(varName);
+ if (!buffer || !*buffer) {
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+#endif
+ const qlonglong value = qstrtoll(buffer, Q_NULLPTR, 0, ok);
+ if (int(value) != value) { // this is the check in QByteArray::toInt(), keep it in sync
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+ return int(value);
+}
+
+/*!
+ \relates <QtGlobal>
\since 5.1
Returns whether the environment variable \a varName is set.
@@ -3910,6 +3947,21 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
otherwise.
+
+ \sa Q_DECL_RELAXED_CONSTEXPR
+*/
+
+/*!
+ \macro Q_DECL_RELAXED_CONSTEXPR
+ \relates <QtGlobal>
+
+ This macro can be used to declare an inline function that can be computed
+ at compile-time according to the relaxed rules from C++14.
+
+ It expands to "constexpr" if your compiler supports C++14 relaxed constant
+ expressions, or to nothing otherwise.
+
+ \sa Q_DECL_CONSTEXPR
*/
/*!