summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-03-06 13:32:31 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-09 19:39:48 +0200
commit442a6ef029b56f706bc207cca76549d418008256 (patch)
tree0b616d55cef62dcc2be938d5fddcafb02a40428e /src/corelib/global/qglobal.cpp
parent1ec8df439a1b3d82c6f4d443c22fc9bb00566d1e (diff)
Add QSysInfo::osType()
This function returns the OS kernel type. It's usually the same as the first part of the mkspec, in qmake, or the result of uname. Usually, because it's not the case for a few systems, like Android, OS X, iOS, BlackBerry, etc. Change-Id: I295d92048d33ef02987e8696772ea89e925428d3 Reviewed-by: Jake Petroules <jake.petroules@petroules.com> Reviewed-by: Sergio Ahumada <sahumada@blackberry.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 94ce29d095..1d9c47820b 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -81,6 +81,10 @@
#include <private/qjni_p.h>
#endif
+#ifdef Q_OS_UNIX
+#include <sys/utsname.h>
+#endif
+
#include "archdetect.cpp"
QT_BEGIN_NAMESPACE
@@ -2064,6 +2068,74 @@ QString QSysInfo::fullCpuArchitecture()
}
/*!
+ \since 5.4
+
+ Returns the type of the operating system Qt was compiled for. It's also the
+ operating system the application is running on, unless the host operating
+ system is running a form of compatibility layer.
+
+ Values returned by this function are stable and will not change over time,
+ so applications can rely on the returned value as an identifier, except
+ that new OS types may be added over time.
+
+ \b{Android note}: this function returns "android" for Linux systems running
+ Android userspace, notably when using the Bionic library. For all other
+ Linux systems, regardless of C library being used, it returns "linux".
+
+ \b{BlackBerry note}: this function returns "blackberry" for QNX systems
+ running the BlackBerry userspace, but "qnx" for all other QNX-based
+ systems.
+
+ \b{Darwin, OS X and iOS note}: this function returns "osx" for OS X
+ systems, "ios" for iOS systems and "darwin" in case the system could not be
+ determined.
+
+ \b{FreeBSD note}: this function returns "freebsd" for systems running the
+ FreeBSD kernel, regardless of whether the userspace runs the traditional
+ BSD code or whether it's the GNU system (Debian GNU/kFreeBSD).
+
+ \sa QFileSelector
+*/
+QString QSysInfo::osType()
+{
+ // similar, but not identical to QFileSelectorPrivate::platformSelectors
+#if defined(Q_OS_WINPHONE)
+ return QStringLiteral("winphone");
+#elif defined(Q_OS_WINRT)
+ return QStringLiteral("winrt");
+#elif defined(Q_OS_WINCE)
+ return QStringLiteral("wince");
+#elif defined(Q_OS_WIN)
+ return QStringLiteral("windows");
+
+#elif defined(Q_OS_BLACKBERRY)
+ return QStringLiteral("blackberry");
+#elif defined(Q_OS_QNX)
+ return QStringLiteral("qnx");
+
+#elif defined(Q_OS_ANDROID)
+ return QStringLiteral("android");
+#elif defined(Q_OS_LINUX)
+ return QStringLiteral("linux");
+
+#elif defined(Q_OS_IOS)
+ return QStringLiteral("ios");
+#elif defined(Q_OS_OSX)
+ return QStringLiteral("osx");
+#elif defined(Q_OS_DARWIN)
+ return QStringLiteral("darwin");
+
+#elif defined(Q_OS_FREEBSD_KERNEL)
+ return QStringLiteral("freebsd");
+#elif defined(Q_OS_UNIX)
+ struct utsname u;
+ if (uname(&u) != -1)
+ return QString(u.sysname).toLower();
+#endif
+ return QStringLiteral("unknown");
+}
+
+/*!
\macro void Q_ASSERT(bool test)
\relates <QtGlobal>