2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2016-01-21 01:24:57 +00:00
|
|
|
** Copyright (C) 2016 Intel Corporation.
|
2016-01-15 07:08:27 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtCore module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 07:08:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-15 07:08:27 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qplatformdefs.h"
|
|
|
|
#include "qstring.h"
|
|
|
|
#include "qvector.h"
|
|
|
|
#include "qlist.h"
|
|
|
|
#include "qthreadstorage.h"
|
|
|
|
#include "qdir.h"
|
|
|
|
#include "qdatetime.h"
|
2016-04-23 03:54:51 +00:00
|
|
|
#include "qoperatingsystemversion.h"
|
|
|
|
#include "qoperatingsystemversion_p.h"
|
2014-09-07 19:11:55 +00:00
|
|
|
#include <private/qlocale_tools_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-04-24 08:47:29 +00:00
|
|
|
#include <qmutex.h>
|
2014-12-19 10:07:47 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
|
|
|
#include <private/qthread_p.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifndef QT_NO_EXCEPTIONS
|
|
|
|
# include <string>
|
|
|
|
# include <exception>
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 09:25:46 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#if defined(Q_CC_MSVC)
|
|
|
|
# include <crtdbg.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
#ifdef Q_OS_WINRT
|
2015-12-16 14:33:42 +00:00
|
|
|
#include <Ws2tcpip.h>
|
|
|
|
#endif // Q_OS_WINRT
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-06-15 10:55:08 +00:00
|
|
|
#if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL)
|
2011-04-27 10:05:43 +00:00
|
|
|
# include <envLib.h>
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 09:49:43 +00:00
|
|
|
#if defined(Q_OS_ANDROID)
|
2013-10-11 12:55:33 +00:00
|
|
|
#include <private/qjni_p.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-07 21:33:56 +00:00
|
|
|
#if defined(Q_OS_SOLARIS)
|
|
|
|
# include <sys/systeminfo.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-06 21:32:31 +00:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include <sys/utsname.h>
|
2014-03-06 23:08:53 +00:00
|
|
|
#include <private/qcore_unix_p.h>
|
2014-03-06 21:32:31 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
#ifdef Q_OS_BSD4
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-06 20:58:21 +00:00
|
|
|
#include "archdetect.cpp"
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2012-06-11 10:28:22 +00:00
|
|
|
#if !QT_DEPRECATED_SINCE(5, 0)
|
|
|
|
// Make sure they're defined to be exported
|
|
|
|
Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
|
|
|
|
Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-11-05 17:45:44 +00:00
|
|
|
// Statically check assumptions about the environment we're running
|
|
|
|
// in. The idea here is to error or warn if otherwise implicit Qt
|
|
|
|
// assumptions are not fulfilled on new hardware or compilers
|
|
|
|
// (if this list becomes too long, consider factoring into a separate file)
|
|
|
|
Q_STATIC_ASSERT_X(sizeof(int) == 4, "Qt assumes that int is 32 bits");
|
|
|
|
Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
|
2015-10-22 19:54:45 +00:00
|
|
|
Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
|
2013-11-05 17:45:44 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\class QFlag
|
2012-08-23 10:22:38 +00:00
|
|
|
\inmodule QtCore
|
2011-04-27 10:05:43 +00:00
|
|
|
\brief The QFlag class is a helper data type for QFlags.
|
|
|
|
|
|
|
|
It is equivalent to a plain \c int, except with respect to
|
|
|
|
function overloading and type conversions. You should never need
|
|
|
|
to use this class in your applications.
|
|
|
|
|
|
|
|
\sa QFlags
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlag::QFlag(int value)
|
|
|
|
|
|
|
|
Constructs a QFlag object that stores the given \a value.
|
|
|
|
*/
|
|
|
|
|
2013-06-28 21:43:27 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlag::QFlag(uint value)
|
2017-01-02 09:58:10 +00:00
|
|
|
\since 5.3
|
2013-06-28 21:43:27 +00:00
|
|
|
|
|
|
|
Constructs a QFlag object that stores the given \a value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlag::QFlag(short value)
|
|
|
|
\since 5.3
|
|
|
|
|
|
|
|
Constructs a QFlag object that stores the given \a value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlag::QFlag(ushort value)
|
2017-01-02 09:58:10 +00:00
|
|
|
\since 5.3
|
2013-06-28 21:43:27 +00:00
|
|
|
|
|
|
|
Constructs a QFlag object that stores the given \a value.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlag::operator int() const
|
|
|
|
|
|
|
|
Returns the value stored by the QFlag object.
|
|
|
|
*/
|
|
|
|
|
2013-06-28 21:43:27 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlag::operator uint() const
|
2017-01-02 09:58:10 +00:00
|
|
|
\since 5.3
|
2013-06-28 21:43:27 +00:00
|
|
|
|
|
|
|
Returns the value stored by the QFlag object.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\class QFlags
|
2012-08-23 10:22:38 +00:00
|
|
|
\inmodule QtCore
|
2011-04-27 10:05:43 +00:00
|
|
|
\brief The QFlags class provides a type-safe way of storing
|
|
|
|
OR-combinations of enum values.
|
|
|
|
|
|
|
|
|
|
|
|
\ingroup tools
|
|
|
|
|
|
|
|
The QFlags<Enum> class is a template class, where Enum is an enum
|
|
|
|
type. QFlags is used throughout Qt for storing combinations of
|
|
|
|
enum values.
|
|
|
|
|
|
|
|
The traditional C++ approach for storing OR-combinations of enum
|
|
|
|
values is to use an \c int or \c uint variable. The inconvenience
|
|
|
|
with this approach is that there's no type checking at all; any
|
|
|
|
enum value can be OR'd with any other enum value and passed on to
|
|
|
|
a function that takes an \c int or \c uint.
|
|
|
|
|
|
|
|
Qt uses QFlags to provide type safety. For example, the
|
|
|
|
Qt::Alignment type is simply a typedef for
|
|
|
|
QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
|
|
|
|
Qt::Alignment parameter, which means that any combination of
|
2012-09-25 11:30:49 +00:00
|
|
|
Qt::AlignmentFlag values, or 0, is legal:
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If you try to pass a value from another enum or just a plain
|
|
|
|
integer other than 0, the compiler will report an error. If you
|
|
|
|
need to cast integer values to flags in a untyped fashion, you can
|
|
|
|
use the explicit QFlags constructor as cast operator.
|
|
|
|
|
|
|
|
If you want to use QFlags for your own enum types, use
|
|
|
|
the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 1
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
You can then use the \c MyClass::Options type to store
|
|
|
|
combinations of \c MyClass::Option values.
|
|
|
|
|
|
|
|
\section1 Flags and the Meta-Object System
|
|
|
|
|
|
|
|
The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
|
|
|
|
system, so they cannot be used by Qt Script or edited in Qt Designer.
|
2015-03-14 11:17:05 +00:00
|
|
|
To make the flags available for these purposes, the Q_FLAG() macro must
|
2011-04-27 10:05:43 +00:00
|
|
|
be used:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp meta-object flags
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\section1 Naming Convention
|
|
|
|
|
|
|
|
A sensible naming convention for enum types and associated QFlags
|
|
|
|
types is to give a singular name to the enum type (e.g., \c
|
|
|
|
Option) and a plural name to the QFlags type (e.g., \c Options).
|
|
|
|
When a singular name is desired for the QFlags type (e.g., \c
|
|
|
|
Alignment), you can use \c Flag as the suffix for the enum type
|
|
|
|
(e.g., \c AlignmentFlag).
|
|
|
|
|
|
|
|
\sa QFlag
|
|
|
|
*/
|
|
|
|
|
2012-09-20 13:06:11 +00:00
|
|
|
/*!
|
|
|
|
\typedef QFlags::Int
|
|
|
|
\since 5.0
|
|
|
|
|
|
|
|
Typedef for the integer type used for storage as well as for
|
|
|
|
implicit conversion. Either \c int or \c{unsigned int}, depending
|
|
|
|
on whether the enum's underlying type is signed or unsigned.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\typedef QFlags::enum_type
|
|
|
|
|
|
|
|
Typedef for the Enum template type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags::QFlags(const QFlags &other)
|
|
|
|
|
|
|
|
Constructs a copy of \a other.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags::QFlags(Enum flag)
|
|
|
|
|
|
|
|
Constructs a QFlags object storing the given \a flag.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags::QFlags(Zero zero)
|
|
|
|
|
|
|
|
Constructs a QFlags object with no flags set. \a zero must be a
|
|
|
|
literal 0 value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags::QFlags(QFlag value)
|
|
|
|
|
|
|
|
Constructs a QFlags object initialized with the given integer \a
|
|
|
|
value.
|
|
|
|
|
|
|
|
The QFlag type is a helper type. By using it here instead of \c
|
|
|
|
int, we effectively ensure that arbitrary enum values cannot be
|
|
|
|
cast to a QFlags, whereas untyped enum values (i.e., \c int
|
|
|
|
values) can.
|
|
|
|
*/
|
|
|
|
|
2014-06-22 18:20:48 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlags::QFlags(std::initializer_list<Enum> flags)
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Constructs a QFlags object initialized with all \a flags
|
|
|
|
combined using the bitwise OR operator.
|
|
|
|
|
|
|
|
\sa operator|=(), operator|()
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator=(const QFlags &other)
|
|
|
|
|
|
|
|
Assigns \a other to this object and returns a reference to this
|
|
|
|
object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator&=(int mask)
|
|
|
|
|
|
|
|
Performs a bitwise AND operation with \a mask and stores the
|
|
|
|
result in this QFlags object. Returns a reference to this object.
|
|
|
|
|
|
|
|
\sa operator&(), operator|=(), operator^=()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator&=(uint mask)
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
2013-05-08 16:02:02 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator&=(Enum mask)
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator|=(QFlags other)
|
|
|
|
|
|
|
|
Performs a bitwise OR operation with \a other and stores the
|
|
|
|
result in this QFlags object. Returns a reference to this object.
|
|
|
|
|
|
|
|
\sa operator|(), operator&=(), operator^=()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator|=(Enum other)
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator^=(QFlags other)
|
|
|
|
|
|
|
|
Performs a bitwise XOR operation with \a other and stores the
|
|
|
|
result in this QFlags object. Returns a reference to this object.
|
|
|
|
|
|
|
|
\sa operator^(), operator&=(), operator|=()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags &QFlags::operator^=(Enum other)
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2012-09-20 13:06:11 +00:00
|
|
|
\fn QFlags::operator Int() const
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Returns the value stored in the QFlags object as an integer.
|
2012-09-20 13:06:11 +00:00
|
|
|
|
|
|
|
\sa Int
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator|(QFlags other) const
|
|
|
|
|
|
|
|
Returns a QFlags object containing the result of the bitwise OR
|
|
|
|
operation on this object and \a other.
|
|
|
|
|
|
|
|
\sa operator|=(), operator^(), operator&(), operator~()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator|(Enum other) const
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator^(QFlags other) const
|
|
|
|
|
|
|
|
Returns a QFlags object containing the result of the bitwise XOR
|
|
|
|
operation on this object and \a other.
|
|
|
|
|
|
|
|
\sa operator^=(), operator&(), operator|(), operator~()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator^(Enum other) const
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator&(int mask) const
|
|
|
|
|
|
|
|
Returns a QFlags object containing the result of the bitwise AND
|
|
|
|
operation on this object and \a mask.
|
|
|
|
|
|
|
|
\sa operator&=(), operator|(), operator^(), operator~()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator&(uint mask) const
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator&(Enum mask) const
|
|
|
|
|
|
|
|
\overload
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QFlags QFlags::operator~() const
|
|
|
|
|
|
|
|
Returns a QFlags object that contains the bitwise negation of
|
|
|
|
this object.
|
|
|
|
|
|
|
|
\sa operator&(), operator|(), operator^()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool QFlags::operator!() const
|
|
|
|
|
2013-10-02 14:51:05 +00:00
|
|
|
Returns \c true if no flag is set (i.e., if the value stored by the
|
|
|
|
QFlags object is 0); otherwise returns \c false.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool QFlags::testFlag(Enum flag) const
|
|
|
|
\since 4.2
|
|
|
|
|
2014-01-27 14:20:25 +00:00
|
|
|
Returns \c true if the \a flag is set, otherwise \c false.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-02 09:16:24 +00:00
|
|
|
/*!
|
2016-03-11 16:02:09 +00:00
|
|
|
\fn QFlags QFlags::setFlag(Enum flag, bool on)
|
2016-02-02 09:16:24 +00:00
|
|
|
\since 5.7
|
|
|
|
|
|
|
|
Sets the indicated \a flag if \a on is \c true or unsets it if
|
2016-02-19 06:36:00 +00:00
|
|
|
\a on is \c false. Returns a reference to this object.
|
2016-02-02 09:16:24 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DISABLE_COPY(Class)
|
|
|
|
\relates QObject
|
|
|
|
|
|
|
|
Disables the use of copy constructors and assignment operators
|
|
|
|
for the given \a Class.
|
|
|
|
|
|
|
|
Instances of subclasses of QObject should not be thought of as
|
|
|
|
values that can be copied or assigned, but as unique identities.
|
|
|
|
This means that when you create your own subclass of QObject
|
|
|
|
(director or indirect), you should \e not give it a copy constructor
|
|
|
|
or an assignment operator. However, it may not enough to simply
|
|
|
|
omit them from your class, because, if you mistakenly write some code
|
|
|
|
that requires a copy constructor or an assignment operator (it's easy
|
|
|
|
to do), your compiler will thoughtfully create it for you. You must
|
|
|
|
do more.
|
|
|
|
|
|
|
|
The curious user will have seen that the Qt classes derived
|
|
|
|
from QObject typically include this macro in a private section:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 43
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
It declares a copy constructor and an assignment operator in the
|
|
|
|
private section, so that if you use them by mistake, the compiler
|
|
|
|
will report an error.
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 44
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
But even this might not catch absolutely every case. You might be
|
|
|
|
tempted to do something like this:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 45
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
First of all, don't do that. Most compilers will generate code that
|
|
|
|
uses the copy constructor, so the privacy violation error will be
|
|
|
|
reported, but your C++ compiler is not required to generate code for
|
|
|
|
this statement in a specific way. It could generate code using
|
|
|
|
\e{neither} the copy constructor \e{nor} the assignment operator we
|
|
|
|
made private. In that case, no error would be reported, but your
|
|
|
|
application would probably crash when you called a member function
|
|
|
|
of \c{w}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECLARE_FLAGS(Flags, Enum)
|
|
|
|
\relates QFlags
|
|
|
|
|
|
|
|
The Q_DECLARE_FLAGS() macro expands to
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 2
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\a Enum is the name of an existing enum type, whereas \a Flags is
|
|
|
|
the name of the QFlags<\e{Enum}> typedef.
|
|
|
|
|
|
|
|
See the QFlags documentation for details.
|
|
|
|
|
|
|
|
\sa Q_DECLARE_OPERATORS_FOR_FLAGS()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
|
|
|
|
\relates QFlags
|
|
|
|
|
|
|
|
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
|
|
|
|
operator|() functions for \a Flags, which is of type QFlags<T>.
|
|
|
|
|
|
|
|
See the QFlags documentation for details.
|
|
|
|
|
|
|
|
\sa Q_DECLARE_FLAGS()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\headerfile <QtGlobal>
|
|
|
|
\title Global Qt Declarations
|
|
|
|
\ingroup funclists
|
|
|
|
|
|
|
|
\brief The <QtGlobal> header file includes the fundamental global
|
|
|
|
declarations. It is included by most other Qt header files.
|
|
|
|
|
|
|
|
The global declarations include \l{types}, \l{functions} and
|
|
|
|
\l{macros}.
|
|
|
|
|
|
|
|
The type definitions are partly convenience definitions for basic
|
|
|
|
types (some of which guarantee certain bit-sizes on all platforms
|
|
|
|
supported by Qt), partly types related to Qt message handling. The
|
|
|
|
functions are related to generating messages, Qt version handling
|
|
|
|
and comparing and adjusting object values. And finally, some of
|
|
|
|
the declared macros enable programmers to add compiler or platform
|
|
|
|
specific code to their applications, while others are convenience
|
|
|
|
macros for larger operations.
|
|
|
|
|
|
|
|
\section1 Types
|
|
|
|
|
|
|
|
The header file declares several type definitions that guarantee a
|
|
|
|
specified bit-size on all platforms supported by Qt for various
|
|
|
|
basic types, for example \l qint8 which is a signed char
|
|
|
|
guaranteed to be 8-bit on all platforms supported by Qt. The
|
|
|
|
header file also declares the \l qlonglong type definition for \c
|
|
|
|
{long long int } (\c __int64 on Windows).
|
|
|
|
|
|
|
|
Several convenience type definitions are declared: \l qreal for \c
|
|
|
|
double, \l uchar for \c unsigned char, \l uint for \c unsigned
|
|
|
|
int, \l ulong for \c unsigned long and \l ushort for \c unsigned
|
|
|
|
short.
|
|
|
|
|
|
|
|
Finally, the QtMsgType definition identifies the various messages
|
|
|
|
that can be generated and sent to a Qt message handler;
|
2012-04-02 11:48:06 +00:00
|
|
|
QtMessageHandler is a type definition for a pointer to a function with
|
QtDebug: Include file, line, function information
Record the file, line, and function where a qDebug, qWarning, qCritical
or qFatal call happens, and make this information available in a custom
message handler.
The patch uses the C preprocessor to replace qDebug, qWarning, ... with
a line that also records the current file, line, and function. Custom
message handlers can access this information via a new QMessageLogContext
argument.
Change-Id: I0a9b89c1d137e41775932d3b1a35da4ebf12d18d
Reviewed-by: David Faure <faure@kde.org>
2012-01-17 15:20:45 +00:00
|
|
|
the signature
|
|
|
|
\c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}.
|
|
|
|
QMessageLogContext class contains the line, file, and function the
|
|
|
|
message was logged at. This information is created by the QMessageLogger
|
|
|
|
class.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\section1 Functions
|
|
|
|
|
|
|
|
The <QtGlobal> header file contains several functions comparing
|
|
|
|
and adjusting an object's value. These functions take a template
|
|
|
|
type as argument: You can retrieve the absolute value of an object
|
|
|
|
using the qAbs() function, and you can bound a given object's
|
|
|
|
value by given minimum and maximum values using the qBound()
|
|
|
|
function. You can retrieve the minimum and maximum of two given
|
|
|
|
objects using qMin() and qMax() respectively. All these functions
|
|
|
|
return a corresponding template type; the template types can be
|
|
|
|
replaced by any other type.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 3
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
<QtGlobal> also contains functions that generate messages from the
|
2014-12-04 15:57:32 +00:00
|
|
|
given string argument: qDebug(), qInfo(), qWarning(), qCritical(),
|
|
|
|
and qFatal(). These functions call the message handler
|
|
|
|
with the given message.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 4
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
The remaining functions are qRound() and qRound64(), which both
|
2016-04-08 09:54:52 +00:00
|
|
|
accept a \c double or \c float value as their argument returning
|
|
|
|
the value rounded up to the nearest integer and 64-bit integer
|
|
|
|
respectively, the qInstallMessageHandler() function which installs
|
|
|
|
the given QtMessageHandler, and the qVersion() function which
|
|
|
|
returns the version number of Qt at run-time as a string.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\section1 Macros
|
|
|
|
|
|
|
|
The <QtGlobal> header file provides a range of macros (Q_CC_*)
|
|
|
|
that are defined if the application is compiled using the
|
|
|
|
specified platforms. For example, the Q_CC_SUN macro is defined if
|
|
|
|
the application is compiled using Forte Developer, or Sun Studio
|
|
|
|
C++. The header file also declares a range of macros (Q_OS_*)
|
|
|
|
that are defined for the specified platforms. For example,
|
2013-06-17 02:08:09 +00:00
|
|
|
Q_OS_UNIX which is defined for the Unix-based systems.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
The purpose of these macros is to enable programmers to add
|
|
|
|
compiler or platform specific code to their application.
|
|
|
|
|
|
|
|
The remaining macros are convenience macros for larger operations:
|
|
|
|
The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the
|
|
|
|
possibility of marking text for dynamic translation,
|
|
|
|
i.e. translation without changing the stored source text. The
|
|
|
|
Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
|
|
|
|
level of refinement. The Q_FOREACH() and foreach() macros
|
|
|
|
implement Qt's foreach loop.
|
|
|
|
|
|
|
|
The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
|
|
|
|
64-bit integer literals in a platform-independent way. The
|
|
|
|
Q_CHECK_PTR() macro prints a warning containing the source code's
|
|
|
|
file name and line number, saying that the program ran out of
|
2014-03-06 07:56:52 +00:00
|
|
|
memory, if the pointer is 0. The qPrintable() and qUtf8Printable()
|
|
|
|
macros represent an easy way of printing text.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Finally, the QT_POINTER_SIZE macro expands to the size of a
|
|
|
|
pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
|
|
|
|
expand to a numeric value or a string, respectively, specifying
|
|
|
|
Qt's version number, i.e the version the application is compiled
|
|
|
|
against.
|
|
|
|
|
|
|
|
\sa <QtAlgorithms>, QSysInfo
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef qreal
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2013-11-28 15:08:53 +00:00
|
|
|
Typedef for \c double unless Qt is configured with the
|
|
|
|
\c{-qreal float} option.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef uchar
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Convenience typedef for \c{unsigned char}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef ushort
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Convenience typedef for \c{unsigned short}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef uint
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Convenience typedef for \c{unsigned int}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef ulong
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Convenience typedef for \c{unsigned long}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef qint8
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{signed char}. This type is guaranteed to be 8-bit
|
|
|
|
on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef quint8
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{unsigned char}. This type is guaranteed to
|
|
|
|
be 8-bit on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef qint16
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{signed short}. This type is guaranteed to be
|
|
|
|
16-bit on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef quint16
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{unsigned short}. This type is guaranteed to
|
|
|
|
be 16-bit on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef qint32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{signed int}. This type is guaranteed to be 32-bit
|
|
|
|
on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef quint32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{unsigned int}. This type is guaranteed to
|
|
|
|
be 32-bit on all platforms supported by Qt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef qint64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{long long int} (\c __int64 on Windows). This type
|
|
|
|
is guaranteed to be 64-bit on all platforms supported by Qt.
|
|
|
|
|
|
|
|
Literals of this type can be created using the Q_INT64_C() macro:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 5
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_INT64_C(), quint64, qlonglong
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef quint64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
|
|
|
|
Windows). This type is guaranteed to be 64-bit on all platforms
|
|
|
|
supported by Qt.
|
|
|
|
|
|
|
|
Literals of this type can be created using the Q_UINT64_C()
|
|
|
|
macro:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 6
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_UINT64_C(), qint64, qulonglong
|
|
|
|
*/
|
|
|
|
|
2013-02-19 23:52:48 +00:00
|
|
|
/*!
|
|
|
|
\typedef qintptr
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Integral type for representing pointers in a signed integer (useful for
|
|
|
|
hashing, etc.).
|
|
|
|
|
|
|
|
Typedef for either qint32 or qint64. This type is guaranteed to
|
|
|
|
be the same size as a pointer on all platforms supported by Qt. On
|
|
|
|
a system with 32-bit pointers, qintptr is a typedef for qint32;
|
|
|
|
on a system with 64-bit pointers, qintptr is a typedef for
|
|
|
|
qint64.
|
|
|
|
|
|
|
|
Note that qintptr is signed. Use quintptr for unsigned values.
|
|
|
|
|
|
|
|
\sa qptrdiff, qint32, qint64
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\typedef quintptr
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2013-02-19 23:52:48 +00:00
|
|
|
Integral type for representing pointers in an unsigned integer (useful for
|
|
|
|
hashing, etc.).
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Typedef for either quint32 or quint64. This type is guaranteed to
|
|
|
|
be the same size as a pointer on all platforms supported by Qt. On
|
|
|
|
a system with 32-bit pointers, quintptr is a typedef for quint32;
|
|
|
|
on a system with 64-bit pointers, quintptr is a typedef for
|
|
|
|
quint64.
|
|
|
|
|
|
|
|
Note that quintptr is unsigned. Use qptrdiff for signed values.
|
|
|
|
|
|
|
|
\sa qptrdiff, quint32, quint64
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef qptrdiff
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Integral type for representing pointer differences.
|
|
|
|
|
|
|
|
Typedef for either qint32 or qint64. This type is guaranteed to be
|
|
|
|
the same size as a pointer on all platforms supported by Qt. On a
|
|
|
|
system with 32-bit pointers, quintptr is a typedef for quint32; on
|
|
|
|
a system with 64-bit pointers, quintptr is a typedef for quint64.
|
|
|
|
|
|
|
|
Note that qptrdiff is signed. Use quintptr for unsigned values.
|
|
|
|
|
|
|
|
\sa quintptr, qint32, qint64
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum QtMsgType
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This enum describes the messages that can be sent to a message
|
2014-02-15 03:54:53 +00:00
|
|
|
handler (QtMessageHandler). You can use the enum to identify and
|
2011-04-27 10:05:43 +00:00
|
|
|
associate the various message types with the appropriate
|
|
|
|
actions.
|
|
|
|
|
|
|
|
\value QtDebugMsg
|
|
|
|
A message generated by the qDebug() function.
|
2014-12-04 15:57:32 +00:00
|
|
|
\value QtInfoMsg
|
|
|
|
A message generated by the qInfo() function.
|
2011-04-27 10:05:43 +00:00
|
|
|
\value QtWarningMsg
|
|
|
|
A message generated by the qWarning() function.
|
|
|
|
\value QtCriticalMsg
|
|
|
|
A message generated by the qCritical() function.
|
|
|
|
\value QtFatalMsg
|
|
|
|
A message generated by the qFatal() function.
|
|
|
|
\value QtSystemMsg
|
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\c QtInfoMsg was added in Qt 5.5.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-04-02 11:48:06 +00:00
|
|
|
\sa QtMessageHandler, qInstallMessageHandler()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-21 16:47:26 +00:00
|
|
|
/*! \typedef QFunctionPointer
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This is a typedef for \c{void (*)()}, a pointer to a function that takes
|
|
|
|
no arguments and returns void.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*! \macro qint64 Q_INT64_C(literal)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Wraps the signed 64-bit integer \a literal in a
|
|
|
|
platform-independent way.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 8
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qint64, Q_UINT64_C()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \macro quint64 Q_UINT64_C(literal)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Wraps the unsigned 64-bit integer \a literal in a
|
|
|
|
platform-independent way.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 9
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa quint64, Q_INT64_C()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \typedef qlonglong
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{long long int} (\c __int64 on Windows). This is
|
|
|
|
the same as \l qint64.
|
|
|
|
|
|
|
|
\sa qulonglong, qint64
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\typedef qulonglong
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
|
|
|
|
Windows). This is the same as \l quint64.
|
|
|
|
|
|
|
|
\sa quint64, qlonglong
|
|
|
|
*/
|
|
|
|
|
2012-09-03 08:13:34 +00:00
|
|
|
/*! \fn T qAbs(const T &value)
|
2011-04-27 10:05:43 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Compares \a value to the 0 of type T and returns the absolute
|
|
|
|
value. Thus if T is \e {double}, then \a value is compared to
|
|
|
|
\e{(double) 0}.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 10
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-08 09:54:52 +00:00
|
|
|
/*! \fn int qRound(double value)
|
2011-04-27 10:05:43 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Rounds \a value to the nearest integer.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2016-04-08 09:54:52 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 11A
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-08 09:54:52 +00:00
|
|
|
/*! \fn int qRound(float value)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Rounds \a value to the nearest integer.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 11B
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn qint64 qRound64(double value)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Rounds \a value to the nearest 64-bit integer.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 12A
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn qint64 qRound64(float value)
|
2011-04-27 10:05:43 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Rounds \a value to the nearest 64-bit integer.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2016-04-08 09:54:52 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 12B
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn const T &qMin(const T &value1, const T &value2)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns the minimum of \a value1 and \a value2.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 13
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qMax(), qBound()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn const T &qMax(const T &value1, const T &value2)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns the maximum of \a value1 and \a value2.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 14
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qMin(), qBound()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn const T &qBound(const T &min, const T &value, const T &max)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns \a value bounded by \a min and \a max. This is equivalent
|
|
|
|
to qMax(\a min, qMin(\a value, \a max)).
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 15
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qMin(), qMax()
|
|
|
|
*/
|
|
|
|
|
2015-11-10 17:57:40 +00:00
|
|
|
/*! \fn auto qOverload(T functionPointer)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
|
2016-02-15 21:29:44 +00:00
|
|
|
Returns a pointer to an overloaded function. The template
|
2015-11-10 17:57:40 +00:00
|
|
|
parameter is the list of the argument types of the function.
|
|
|
|
\a functionPointer is the pointer to the (member) function:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 52
|
|
|
|
|
2016-02-15 21:29:44 +00:00
|
|
|
If a member function is also const-overloaded \l qConstOverload and
|
|
|
|
\l qNonConstOverload need to be used.
|
2015-11-10 17:57:40 +00:00
|
|
|
|
2016-02-15 21:29:44 +00:00
|
|
|
qOverload() requires C++14 enabled. In C++11-only code, the helper
|
|
|
|
classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
|
2015-11-10 17:57:40 +00:00
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 53
|
|
|
|
|
2016-09-07 00:16:11 +00:00
|
|
|
\sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
|
|
|
|
and Functor-Based Connections}
|
2015-11-10 17:57:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn auto qConstOverload(T memberFunctionPointer)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
|
2016-03-24 09:34:55 +00:00
|
|
|
Returns the \a memberFunctionPointer pointer to a constant member function:
|
2015-11-10 17:57:40 +00:00
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 54
|
|
|
|
|
2016-09-07 00:16:11 +00:00
|
|
|
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
|
|
|
and Functor-Based Connections}
|
2015-11-10 17:57:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \fn auto qNonConstOverload(T memberFunctionPointer)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
|
2016-03-24 15:30:55 +00:00
|
|
|
Returns the \a memberFunctionPointer pointer to a non-constant member function:
|
2015-11-10 17:57:40 +00:00
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 54
|
|
|
|
|
2016-09-07 00:16:11 +00:00
|
|
|
\sa qOverload, qNonConstOverload, {Differences between String-Based
|
|
|
|
and Functor-Based Connections}
|
2015-11-10 17:57:40 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro QT_VERSION_CHECK
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Turns the major, minor and patch numbers of a version into an
|
|
|
|
integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
|
|
|
|
be compared with another similarly processed version id.
|
|
|
|
|
2013-02-26 16:13:44 +00:00
|
|
|
Example:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qt-version-check
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
\sa QT_VERSION
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_VERSION
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro expands a numeric value of the form 0xMMNNPP (MM =
|
|
|
|
major, NN = minor, PP = patch) that specifies Qt's version
|
|
|
|
number. For example, if you compile your application against Qt
|
|
|
|
4.1.2, the QT_VERSION macro will expand to 0x040102.
|
|
|
|
|
|
|
|
You can use QT_VERSION to use the latest Qt features where
|
|
|
|
available.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 16
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa QT_VERSION_STR, qVersion()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_VERSION_STR
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro expands to a string that specifies Qt's version number
|
|
|
|
(for example, "4.1.2"). This is the version against which the
|
|
|
|
application is compiled.
|
|
|
|
|
|
|
|
\sa qVersion(), QT_VERSION
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns the version number of Qt at run-time as a string (for
|
|
|
|
example, "4.1.2"). This may be a different version than the
|
|
|
|
version the application was compiled against.
|
|
|
|
|
2016-04-26 06:28:42 +00:00
|
|
|
\sa QT_VERSION_STR, QLibraryInfo::version()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-07 08:54:00 +00:00
|
|
|
const char *qVersion() Q_DECL_NOTHROW
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return QT_VERSION_STR;
|
|
|
|
}
|
|
|
|
|
2012-08-07 08:54:00 +00:00
|
|
|
bool qSharedBuild() Q_DECL_NOTHROW
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
#ifdef QT_SHARED
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
System detection routines
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\class QSysInfo
|
2012-08-23 10:22:38 +00:00
|
|
|
\inmodule QtCore
|
2011-04-27 10:05:43 +00:00
|
|
|
\brief The QSysInfo class provides information about the system.
|
|
|
|
|
|
|
|
\list
|
2012-03-01 14:28:31 +00:00
|
|
|
\li \l WordSize specifies the size of a pointer for the platform
|
2011-04-27 10:05:43 +00:00
|
|
|
on which the application is compiled.
|
2012-03-01 14:28:31 +00:00
|
|
|
\li \l ByteOrder specifies whether the platform is big-endian or
|
2011-04-27 10:05:43 +00:00
|
|
|
little-endian.
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
Some constants are defined only on certain platforms. You can use
|
2016-08-03 10:00:41 +00:00
|
|
|
the preprocessor symbols Q_OS_WIN and Q_OS_MACOS to test that
|
|
|
|
the application is compiled under Windows or \macos.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa QLibraryInfo
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum QSysInfo::Sizes
|
|
|
|
|
|
|
|
This enum provides platform-specific information about the sizes of data
|
|
|
|
structures used by the underlying architecture.
|
|
|
|
|
|
|
|
\value WordSize The size in bits of a pointer for the platform on which
|
|
|
|
the application is compiled (32 or 64).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2011-04-27 10:05:43 +00:00
|
|
|
\variable QSysInfo::WindowsVersion
|
|
|
|
\brief the version of the Windows operating system on which the
|
2014-11-06 10:41:54 +00:00
|
|
|
application is run.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2011-04-27 10:05:43 +00:00
|
|
|
\fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
|
|
|
|
\since 4.4
|
|
|
|
|
|
|
|
Returns the version of the Windows operating system on which the
|
2014-11-06 10:41:54 +00:00
|
|
|
application is run, or WV_None if the operating system is not
|
|
|
|
Windows.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2011-04-27 10:05:43 +00:00
|
|
|
\variable QSysInfo::MacintoshVersion
|
|
|
|
\brief the version of the Macintosh operating system on which
|
2014-11-06 10:41:54 +00:00
|
|
|
the application is run.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-20 08:43:02 +00:00
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2012-02-20 08:43:02 +00:00
|
|
|
\fn QSysInfo::MacVersion QSysInfo::macVersion()
|
|
|
|
|
2016-08-03 10:00:41 +00:00
|
|
|
Returns the version of Darwin (\macos or iOS) on which the
|
2014-11-06 10:41:54 +00:00
|
|
|
application is run, or MV_None if the operating system
|
|
|
|
is not a version of Darwin.
|
2012-02-20 08:43:02 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\enum QSysInfo::Endian
|
|
|
|
|
|
|
|
\value BigEndian Big-endian byte order (also called Network byte order)
|
|
|
|
\value LittleEndian Little-endian byte order
|
|
|
|
\value ByteOrder Equals BigEndian or LittleEndian, depending on
|
|
|
|
the platform's byte order.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2011-04-27 10:05:43 +00:00
|
|
|
\enum QSysInfo::WinVersion
|
|
|
|
|
|
|
|
This enum provides symbolic names for the various versions of the
|
|
|
|
Windows operating system. On Windows, the
|
|
|
|
QSysInfo::WindowsVersion variable gives the version of the system
|
|
|
|
on which the application is run.
|
|
|
|
|
|
|
|
MS-DOS-based versions:
|
|
|
|
|
|
|
|
\value WV_32s Windows 3.1 with Win 32s
|
|
|
|
\value WV_95 Windows 95
|
|
|
|
\value WV_98 Windows 98
|
|
|
|
\value WV_Me Windows Me
|
|
|
|
|
|
|
|
NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
|
|
|
|
|
|
|
|
\value WV_NT Windows NT (operating system version 4.0)
|
|
|
|
\value WV_2000 Windows 2000 (operating system version 5.0)
|
|
|
|
\value WV_XP Windows XP (operating system version 5.1)
|
|
|
|
\value WV_2003 Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
|
|
|
|
\value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
|
|
|
|
\value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
|
2012-08-16 21:57:02 +00:00
|
|
|
\value WV_WINDOWS8 Windows 8 (operating system version 6.2)
|
2013-10-24 13:05:34 +00:00
|
|
|
\value WV_WINDOWS8_1 Windows 8.1 (operating system version 6.3), introduced in Qt 5.2
|
2014-12-19 09:58:34 +00:00
|
|
|
\value WV_WINDOWS10 Windows 10 (operating system version 10.0), introduced in Qt 5.5
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
|
|
|
|
|
|
|
|
\value WV_4_0 Operating system version 4.0, corresponds to Windows NT
|
|
|
|
\value WV_5_0 Operating system version 5.0, corresponds to Windows 2000
|
|
|
|
\value WV_5_1 Operating system version 5.1, corresponds to Windows XP
|
|
|
|
\value WV_5_2 Operating system version 5.2, corresponds to Windows Server 2003, Windows Server 2003 R2, Windows Home Server, and Windows XP Professional x64 Edition
|
|
|
|
\value WV_6_0 Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
|
|
|
|
\value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
|
2012-08-16 21:57:02 +00:00
|
|
|
\value WV_6_2 Operating system version 6.2, corresponds to Windows 8
|
2013-10-24 13:05:34 +00:00
|
|
|
\value WV_6_3 Operating system version 6.3, corresponds to Windows 8.1, introduced in Qt 5.2
|
2014-12-19 09:58:34 +00:00
|
|
|
\value WV_10_0 Operating system version 10.0, corresponds to Windows 10, introduced in Qt 5.5
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
The following masks can be used for testing whether a Windows
|
2016-08-16 14:44:02 +00:00
|
|
|
version is MS-DOS-based or NT-based:
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\value WV_DOS_based MS-DOS-based version of Windows
|
|
|
|
\value WV_NT_based NT-based version of Windows
|
|
|
|
|
2014-11-06 10:41:54 +00:00
|
|
|
\value WV_None Operating system other than Windows.
|
|
|
|
|
2016-09-14 06:26:50 +00:00
|
|
|
\omitvalue WV_CE
|
|
|
|
\omitvalue WV_CENET
|
|
|
|
\omitvalue WV_CE_5
|
|
|
|
\omitvalue WV_CE_6
|
|
|
|
\omitvalue WV_CE_based
|
|
|
|
|
2012-01-15 12:51:04 +00:00
|
|
|
\sa MacVersion
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2016-09-18 16:23:31 +00:00
|
|
|
\deprecated
|
2011-04-27 10:05:43 +00:00
|
|
|
\enum QSysInfo::MacVersion
|
|
|
|
|
|
|
|
This enum provides symbolic names for the various versions of the
|
2016-08-03 10:00:41 +00:00
|
|
|
Darwin operating system, covering both \macos and iOS. The
|
2011-04-27 10:05:43 +00:00
|
|
|
QSysInfo::MacintoshVersion variable gives the version of the
|
|
|
|
system on which the application is run.
|
|
|
|
|
2016-08-03 10:00:41 +00:00
|
|
|
\value MV_9 \macos 9
|
|
|
|
\value MV_10_0 \macos 10.0
|
|
|
|
\value MV_10_1 \macos 10.1
|
|
|
|
\value MV_10_2 \macos 10.2
|
|
|
|
\value MV_10_3 \macos 10.3
|
|
|
|
\value MV_10_4 \macos 10.4
|
|
|
|
\value MV_10_5 \macos 10.5
|
|
|
|
\value MV_10_6 \macos 10.6
|
|
|
|
\value MV_10_7 \macos 10.7
|
|
|
|
\value MV_10_8 \macos 10.8
|
|
|
|
\value MV_10_9 \macos 10.9
|
|
|
|
\value MV_10_10 \macos 10.10
|
|
|
|
\value MV_10_11 \macos 10.11
|
|
|
|
\value MV_10_12 \macos 10.12
|
2011-04-27 10:05:43 +00:00
|
|
|
\value MV_Unknown An unknown and currently unsupported platform
|
|
|
|
|
|
|
|
\value MV_CHEETAH Apple codename for MV_10_0
|
|
|
|
\value MV_PUMA Apple codename for MV_10_1
|
|
|
|
\value MV_JAGUAR Apple codename for MV_10_2
|
|
|
|
\value MV_PANTHER Apple codename for MV_10_3
|
|
|
|
\value MV_TIGER Apple codename for MV_10_4
|
|
|
|
\value MV_LEOPARD Apple codename for MV_10_5
|
|
|
|
\value MV_SNOWLEOPARD Apple codename for MV_10_6
|
|
|
|
\value MV_LION Apple codename for MV_10_7
|
2012-05-25 09:51:54 +00:00
|
|
|
\value MV_MOUNTAINLION Apple codename for MV_10_8
|
2013-06-02 10:03:08 +00:00
|
|
|
\value MV_MAVERICKS Apple codename for MV_10_9
|
2014-05-30 21:38:13 +00:00
|
|
|
\value MV_YOSEMITE Apple codename for MV_10_10
|
2015-06-01 16:49:04 +00:00
|
|
|
\value MV_ELCAPITAN Apple codename for MV_10_11
|
2016-06-11 04:13:35 +00:00
|
|
|
\value MV_SIERRA Apple codename for MV_10_12
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-11-18 21:37:59 +00:00
|
|
|
\value MV_IOS iOS (any)
|
|
|
|
\value MV_IOS_4_3 iOS 4.3
|
|
|
|
\value MV_IOS_5_0 iOS 5.0
|
|
|
|
\value MV_IOS_5_1 iOS 5.1
|
|
|
|
\value MV_IOS_6_0 iOS 6.0
|
|
|
|
\value MV_IOS_6_1 iOS 6.1
|
|
|
|
\value MV_IOS_7_0 iOS 7.0
|
|
|
|
\value MV_IOS_7_1 iOS 7.1
|
2014-05-30 21:38:13 +00:00
|
|
|
\value MV_IOS_8_0 iOS 8.0
|
2015-05-02 06:35:06 +00:00
|
|
|
\value MV_IOS_8_1 iOS 8.1
|
|
|
|
\value MV_IOS_8_2 iOS 8.2
|
|
|
|
\value MV_IOS_8_3 iOS 8.3
|
2015-06-01 16:49:04 +00:00
|
|
|
\value MV_IOS_8_4 iOS 8.4
|
|
|
|
\value MV_IOS_9_0 iOS 9.0
|
2016-06-11 04:13:35 +00:00
|
|
|
\value MV_IOS_9_1 iOS 9.1
|
|
|
|
\value MV_IOS_9_2 iOS 9.2
|
|
|
|
\value MV_IOS_9_3 iOS 9.3
|
|
|
|
\value MV_IOS_10_0 iOS 10.0
|
2013-11-18 21:37:59 +00:00
|
|
|
|
2016-06-11 04:39:25 +00:00
|
|
|
\value MV_TVOS tvOS (any)
|
|
|
|
\value MV_TVOS_9_0 tvOS 9.0
|
|
|
|
\value MV_TVOS_9_1 tvOS 9.1
|
|
|
|
\value MV_TVOS_9_2 tvOS 9.2
|
|
|
|
\value MV_TVOS_10_0 tvOS 10.0
|
|
|
|
|
2016-10-19 14:37:53 +00:00
|
|
|
\value MV_WATCHOS watchOS (any)
|
|
|
|
\value MV_WATCHOS_2_0 watchOS 2.0
|
|
|
|
\value MV_WATCHOS_2_1 watchOS 2.1
|
|
|
|
\value MV_WATCHOS_2_2 watchOS 2.2
|
|
|
|
\value MV_WATCHOS_3_0 watchOS 3.0
|
|
|
|
|
2014-11-06 10:41:54 +00:00
|
|
|
\value MV_None Not a Darwin operating system
|
|
|
|
|
2012-01-15 12:51:04 +00:00
|
|
|
\sa WinVersion
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_DARWIN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2016-09-20 10:58:04 +00:00
|
|
|
Defined on Darwin-based operating systems such as \macos, iOS, watchOS, and tvOS.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-08 12:06:36 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_MAC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2016-06-11 04:13:35 +00:00
|
|
|
Deprecated synonym for \c Q_OS_DARWIN. Do not use.
|
2013-05-08 12:06:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2013-07-01 13:12:57 +00:00
|
|
|
\macro Q_OS_OSX
|
2013-05-08 12:06:36 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2016-06-11 04:13:35 +00:00
|
|
|
Deprecated synonym for \c Q_OS_MACOS. Do not use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_MACOS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2016-08-03 10:00:41 +00:00
|
|
|
Defined on \macos.
|
2013-05-08 12:06:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_IOS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on iOS.
|
|
|
|
*/
|
|
|
|
|
2015-09-10 08:04:53 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_WATCHOS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on watchOS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_TVOS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on tvOS.
|
|
|
|
*/
|
|
|
|
|
2013-03-26 10:37:45 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_WIN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on all supported versions of Windows. That is, if
|
2016-08-16 14:44:02 +00:00
|
|
|
\l Q_OS_WIN32, \l Q_OS_WIN64, or \l Q_OS_WINRT is defined.
|
2013-03-26 10:37:45 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_WIN32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2016-08-16 14:44:02 +00:00
|
|
|
Defined on 32-bit and 64-bit versions of Windows.
|
2013-03-26 10:37:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_WIN64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on 64-bit versions of Windows.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-13 09:22:45 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_WINRT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT,
|
|
|
|
and Windows Phone 8.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_CYGWIN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Cygwin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_SOLARIS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Sun Solaris.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_HPUX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on HP-UX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_ULTRIX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on DEC Ultrix.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_LINUX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Linux.
|
|
|
|
*/
|
|
|
|
|
2013-08-21 09:04:44 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_ANDROID
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Android.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_OS_FREEBSD
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on FreeBSD.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_NETBSD
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on NetBSD.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_OPENBSD
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on OpenBSD.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_BSDI
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on BSD/OS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_IRIX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on SGI Irix.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_OSF
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on HP Tru64 UNIX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_SCO
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on SCO OpenServer 5.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_UNIXWARE
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on UnixWare 7, Open UNIX 8.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_AIX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on AIX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_HURD
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on GNU Hurd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_DGUX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on DG/UX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_RELIANT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Reliant UNIX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_DYNIX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on DYNIX/ptx.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_QNX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on QNX Neutrino.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_LYNX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on LynxOS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_BSD4
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Any BSD 4.4 system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_OS_UNIX
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined on Any UNIX BSD/SYSV system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_SYM
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Digital Mars C/C++
|
|
|
|
(used to be Symantec C++).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_MSVC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Microsoft Visual
|
|
|
|
C/C++, Intel C++ for Windows.
|
|
|
|
*/
|
|
|
|
|
2017-01-14 23:26:42 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_CC_CLANG
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Clang.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_CC_BOR
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Borland/Turbo C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_WAT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Watcom C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_GNU
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using GNU C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_COMEAU
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Comeau C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_EDG
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Edison Design Group
|
|
|
|
C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_OC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using CenterLine C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_SUN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Forte Developer, or
|
|
|
|
Sun Studio C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_MIPS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using MIPSpro C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_DEC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using DEC C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_HPACC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using HP aC++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_USLC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using SCO OUDK and UDK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_CDS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Reliant C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_KAI
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using KAI C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_INTEL
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Intel C++ for Linux,
|
|
|
|
Intel C++ for Windows.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_HIGHC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using MetaWare High C/C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_PGI
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Portland Group C++.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_CC_GHS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled using Green Hills
|
|
|
|
Optimizing C++ Compilers.
|
|
|
|
*/
|
|
|
|
|
2012-02-17 08:41:35 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_ALPHA
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for Alpha processors.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_ARM
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for ARM processors. Qt currently
|
|
|
|
supports three optional ARM revisions: \l Q_PROCESSOR_ARM_V5, \l
|
|
|
|
Q_PROCESSOR_ARM_V6, and \l Q_PROCESSOR_ARM_V7.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_ARM_V5
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for ARMv5 processors. The \l
|
|
|
|
Q_PROCESSOR_ARM macro is also defined when Q_PROCESSOR_ARM_V5 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_ARM_V6
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for ARMv6 processors. The \l
|
|
|
|
Q_PROCESSOR_ARM and \l Q_PROCESSOR_ARM_V5 macros are also defined when
|
|
|
|
Q_PROCESSOR_ARM_V6 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_ARM_V7
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for ARMv7 processors. The \l
|
|
|
|
Q_PROCESSOR_ARM, \l Q_PROCESSOR_ARM_V5, and \l Q_PROCESSOR_ARM_V6 macros
|
|
|
|
are also defined when Q_PROCESSOR_ARM_V7 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_AVR32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for AVR32 processors.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_BLACKFIN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for Blackfin processors.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_IA64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for IA-64 processors. This includes
|
|
|
|
all Itanium and Itanium 2 processors.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS processors. Qt currently
|
|
|
|
supports seven MIPS revisions: \l Q_PROCESSOR_MIPS_I, \l
|
|
|
|
Q_PROCESSOR_MIPS_II, \l Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, \l
|
|
|
|
Q_PROCESSOR_MIPS_V, \l Q_PROCESSOR_MIPS_32, and \l Q_PROCESSOR_MIPS_64.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_I
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS-I processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS macro is also defined when Q_PROCESSOR_MIPS_I is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_II
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS-II processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS and \l Q_PROCESSOR_MIPS_I macros are also defined when
|
|
|
|
Q_PROCESSOR_MIPS_II is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS32 processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
|
|
|
|
are also defined when Q_PROCESSOR_MIPS_32 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_III
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS-III processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
|
|
|
|
are also defined when Q_PROCESSOR_MIPS_III is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_IV
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS-IV processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, and \l
|
|
|
|
Q_PROCESSOR_MIPS_III macros are also defined when Q_PROCESSOR_MIPS_IV is
|
|
|
|
defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_V
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS-V processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
|
|
|
|
Q_PROCESSOR_MIPS_III, and \l Q_PROCESSOR_MIPS_IV macros are also defined
|
|
|
|
when Q_PROCESSOR_MIPS_V is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_MIPS_64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for MIPS64 processors. The \l
|
|
|
|
Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
|
|
|
|
Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, and \l Q_PROCESSOR_MIPS_V
|
|
|
|
macros are also defined when Q_PROCESSOR_MIPS_64 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2012-02-17 13:17:54 +00:00
|
|
|
\macro Q_PROCESSOR_POWER
|
2012-02-17 08:41:35 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2012-02-17 13:17:54 +00:00
|
|
|
Defined if the application is compiled for POWER processors. Qt currently
|
|
|
|
supports two Power variants: \l Q_PROCESSOR_POWER_32 and \l
|
|
|
|
Q_PROCESSOR_POWER_64.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
2012-02-17 13:17:54 +00:00
|
|
|
\macro Q_PROCESSOR_POWER_32
|
2012-02-17 08:41:35 +00:00
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2012-02-17 13:17:54 +00:00
|
|
|
Defined if the application is compiled for 32-bit Power processors. The \l
|
|
|
|
Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_32 is
|
|
|
|
defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 13:17:54 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_POWER_64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for 64-bit Power processors. The \l
|
|
|
|
Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_64 is
|
2012-02-17 08:41:35 +00:00
|
|
|
defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_S390
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for S/390 processors. Qt supports
|
|
|
|
one optional variant of S/390: Q_PROCESSOR_S390_X.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_S390_X
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for S/390x processors. The \l
|
|
|
|
Q_PROCESSOR_S390 macro is also defined when Q_PROCESSOR_S390_X is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_SH
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for SuperH processors. Qt currently
|
|
|
|
supports one SuperH revision: \l Q_PROCESSOR_SH_4A.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_SH_4A
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for SuperH 4A processors. The \l
|
|
|
|
Q_PROCESSOR_SH macro is also defined when Q_PROCESSOR_SH_4A is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_SPARC
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for SPARC processors. Qt currently
|
|
|
|
supports one optional SPARC revision: \l Q_PROCESSOR_SPARC_V9.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_SPARC_V9
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for SPARC V9 processors. The \l
|
|
|
|
Q_PROCESSOR_SPARC macro is also defined when Q_PROCESSOR_SPARC_V9 is
|
|
|
|
defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_X86
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for x86 processors. Qt currently
|
|
|
|
supports two x86 variants: \l Q_PROCESSOR_X86_32 and \l Q_PROCESSOR_X86_64.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_X86_32
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for 32-bit x86 processors. This
|
|
|
|
includes all i386, i486, i586, and i686 processors. The \l Q_PROCESSOR_X86
|
|
|
|
macro is also defined when Q_PROCESSOR_X86_32 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\macro Q_PROCESSOR_X86_64
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Defined if the application is compiled for 64-bit x86 processors. This
|
|
|
|
includes all AMD64, Intel 64, and other x86_64/x64 processors. The \l
|
|
|
|
Q_PROCESSOR_X86 macro is also defined when Q_PROCESSOR_X86_64 is defined.
|
2014-03-06 20:58:21 +00:00
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2012-02-17 08:41:35 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-08 09:43:27 +00:00
|
|
|
/*!
|
|
|
|
\macro QT_DISABLE_DEPRECATED_BEFORE
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be defined in the project file to disable functions deprecated in
|
|
|
|
a specified version of Qt or any earlier version. The default version number is 5.0,
|
|
|
|
meaning that functions deprecated in or before Qt 5.0 will not be included.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to
|
|
|
|
disable functions deprecated in Qt 5.1 and earlier. In any release, set
|
|
|
|
QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones
|
|
|
|
deprecated in Qt 5.0
|
2017-03-07 16:52:59 +00:00
|
|
|
|
|
|
|
\sa QT_DEPRECATED_WARNINGS
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_DEPRECATED_WARNINGS
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
If this macro is defined, the compiler will generate warnings if API declared as
|
|
|
|
deprecated by Qt is used.
|
|
|
|
|
|
|
|
\sa QT_DISABLE_DEPRECATED_BEFORE
|
2011-06-08 09:43:27 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#if defined(QT_BUILD_QMAKE)
|
|
|
|
// needed to bootstrap qmake
|
|
|
|
static const unsigned int qt_one = 1;
|
|
|
|
const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
|
|
|
|
#endif
|
|
|
|
|
2013-11-18 21:37:59 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_INCLUDE_NAMESPACE
|
|
|
|
#include "private/qcore_mac_p.h"
|
|
|
|
#include "qnamespace.h"
|
|
|
|
QT_END_INCLUDE_NAMESPACE
|
|
|
|
|
2016-09-18 16:23:31 +00:00
|
|
|
#if QT_DEPRECATED_SINCE(5, 9)
|
2017-01-12 21:56:15 +00:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_DEPRECATED
|
2012-02-20 08:43:02 +00:00
|
|
|
QSysInfo::MacVersion QSysInfo::macVersion()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto version = QOperatingSystemVersion::current();
|
2013-11-18 21:37:59 +00:00
|
|
|
#if defined(Q_OS_OSX)
|
2016-04-23 03:54:51 +00:00
|
|
|
return QSysInfo::MacVersion(Q_MV_OSX(version.majorVersion(), version.minorVersion()));
|
2013-11-18 21:37:59 +00:00
|
|
|
#elif defined(Q_OS_IOS)
|
2016-04-23 03:54:51 +00:00
|
|
|
return QSysInfo::MacVersion(Q_MV_IOS(version.majorVersion(), version.minorVersion()));
|
2016-02-16 14:29:59 +00:00
|
|
|
#elif defined(Q_OS_TVOS)
|
2016-04-23 03:54:51 +00:00
|
|
|
return QSysInfo::MacVersion(Q_MV_TVOS(version.majorVersion(), version.minorVersion()));
|
2016-05-20 06:01:59 +00:00
|
|
|
#elif defined(Q_OS_WATCHOS)
|
2016-04-23 03:54:51 +00:00
|
|
|
return QSysInfo::MacVersion(Q_MV_WATCHOS(version.majorVersion(), version.minorVersion()));
|
2014-06-13 22:59:30 +00:00
|
|
|
#else
|
2011-04-27 10:05:43 +00:00
|
|
|
return QSysInfo::MV_Unknown;
|
2014-06-13 22:59:30 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-02-20 08:43:02 +00:00
|
|
|
const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion();
|
2017-01-12 21:56:15 +00:00
|
|
|
QT_WARNING_POP
|
2016-09-18 16:23:31 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-04-24 11:07:23 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
2016-04-23 03:54:51 +00:00
|
|
|
static const char *osVer_helper(QOperatingSystemVersion version = QOperatingSystemVersion::current())
|
2016-04-23 06:00:52 +00:00
|
|
|
{
|
2016-04-24 11:07:23 +00:00
|
|
|
#ifdef Q_OS_MACOS
|
2016-04-23 03:54:51 +00:00
|
|
|
if (version.majorVersion() == 10) {
|
|
|
|
switch (version.minorVersion()) {
|
2016-04-23 06:00:52 +00:00
|
|
|
case 9:
|
|
|
|
return "Mavericks";
|
|
|
|
case 10:
|
|
|
|
return "Yosemite";
|
|
|
|
case 11:
|
|
|
|
return "El Capitan";
|
2016-06-11 04:39:25 +00:00
|
|
|
case 12:
|
|
|
|
return "Sierra";
|
2016-04-23 06:00:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// unknown, future version
|
2016-04-24 11:07:23 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(version);
|
|
|
|
#endif
|
2016-04-23 06:00:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 09:25:46 +00:00
|
|
|
#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINRT)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_INCLUDE_NAMESPACE
|
|
|
|
#include "qt_windows.h"
|
|
|
|
QT_END_INCLUDE_NAMESPACE
|
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
# ifndef QT_BOOTSTRAPPED
|
|
|
|
class QWindowsSockInit
|
2014-12-19 10:07:47 +00:00
|
|
|
{
|
2015-04-08 21:14:16 +00:00
|
|
|
public:
|
|
|
|
QWindowsSockInit();
|
|
|
|
~QWindowsSockInit();
|
|
|
|
int version;
|
|
|
|
};
|
2014-12-19 10:07:47 +00:00
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
QWindowsSockInit::QWindowsSockInit()
|
|
|
|
: version(0)
|
|
|
|
{
|
|
|
|
//### should we try for 2.2 on all platforms ??
|
|
|
|
WSAData wsadata;
|
|
|
|
|
|
|
|
// IPv6 requires Winsock v2.0 or better.
|
|
|
|
if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) {
|
|
|
|
qWarning("QTcpSocketAPI: WinSock v2.0 initialization failed.");
|
|
|
|
} else {
|
|
|
|
version = 0x20;
|
|
|
|
}
|
2014-12-19 10:07:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
QWindowsSockInit::~QWindowsSockInit()
|
2014-12-19 10:07:47 +00:00
|
|
|
{
|
2015-04-08 21:14:16 +00:00
|
|
|
WSACleanup();
|
2014-12-19 10:07:47 +00:00
|
|
|
}
|
2015-04-08 21:14:16 +00:00
|
|
|
Q_GLOBAL_STATIC(QWindowsSockInit, winsockInit)
|
|
|
|
# endif // QT_BOOTSTRAPPED
|
2014-12-19 10:07:47 +00:00
|
|
|
|
2016-09-18 16:23:31 +00:00
|
|
|
#if QT_DEPRECATED_SINCE(5, 9)
|
2016-12-14 07:25:10 +00:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_DEPRECATED
|
2011-04-27 10:05:43 +00:00
|
|
|
QSysInfo::WinVersion QSysInfo::windowsVersion()
|
|
|
|
{
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto version = QOperatingSystemVersion::current();
|
|
|
|
if (version.majorVersion() == 6 && version.minorVersion() == 1)
|
2016-05-08 05:05:32 +00:00
|
|
|
return QSysInfo::WV_WINDOWS7;
|
2016-04-23 03:54:51 +00:00
|
|
|
if (version.majorVersion() == 6 && version.minorVersion() == 2)
|
2016-05-08 05:05:32 +00:00
|
|
|
return QSysInfo::WV_WINDOWS8;
|
2016-04-23 03:54:51 +00:00
|
|
|
if (version.majorVersion() == 6 && version.minorVersion() == 3)
|
2016-05-08 05:05:32 +00:00
|
|
|
return QSysInfo::WV_WINDOWS8_1;
|
2016-04-23 03:54:51 +00:00
|
|
|
if (version.majorVersion() == 10 && version.minorVersion() == 0)
|
2016-05-08 05:05:32 +00:00
|
|
|
return QSysInfo::WV_WINDOWS10;
|
|
|
|
return QSysInfo::WV_NT_based;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2016-09-18 16:23:31 +00:00
|
|
|
const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
|
2016-12-14 07:25:10 +00:00
|
|
|
QT_WARNING_POP
|
2016-09-18 16:23:31 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-12-07 15:09:15 +00:00
|
|
|
static QString winSp_helper()
|
|
|
|
{
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto osv = qWindowsVersionInfo();
|
|
|
|
const qint16 major = osv.wServicePackMajor;
|
2015-12-07 15:09:15 +00:00
|
|
|
if (major) {
|
|
|
|
QString sp = QStringLiteral(" SP ") + QString::number(major);
|
2016-04-23 03:54:51 +00:00
|
|
|
const qint16 minor = osv.wServicePackMinor;
|
2015-12-07 15:09:15 +00:00
|
|
|
if (minor)
|
|
|
|
sp += QLatin1Char('.') + QString::number(minor);
|
|
|
|
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2016-04-23 03:54:51 +00:00
|
|
|
static const char *osVer_helper(QOperatingSystemVersion version = QOperatingSystemVersion::current())
|
2014-03-06 23:08:53 +00:00
|
|
|
{
|
2016-04-23 03:54:51 +00:00
|
|
|
Q_UNUSED(version);
|
|
|
|
const OSVERSIONINFOEX osver = qWindowsVersionInfo();
|
2016-04-23 06:00:52 +00:00
|
|
|
const bool workstation = osver.wProductType == VER_NT_WORKSTATION;
|
2015-12-08 08:08:31 +00:00
|
|
|
|
2016-04-23 06:00:52 +00:00
|
|
|
#define Q_WINVER(major, minor) (major << 8 | minor)
|
|
|
|
switch (Q_WINVER(osver.dwMajorVersion, osver.dwMinorVersion)) {
|
|
|
|
case Q_WINVER(6, 1):
|
2015-12-08 08:08:31 +00:00
|
|
|
return workstation ? "7" : "Server 2008 R2";
|
2016-04-23 06:00:52 +00:00
|
|
|
case Q_WINVER(6, 2):
|
2015-12-08 08:08:31 +00:00
|
|
|
return workstation ? "8" : "Server 2012";
|
2016-04-23 06:00:52 +00:00
|
|
|
case Q_WINVER(6, 3):
|
2015-12-08 08:08:31 +00:00
|
|
|
return workstation ? "8.1" : "Server 2012 R2";
|
2016-04-23 06:00:52 +00:00
|
|
|
case Q_WINVER(10, 0):
|
2015-12-08 08:08:31 +00:00
|
|
|
return workstation ? "10" : "Server 2016";
|
2014-03-06 23:08:53 +00:00
|
|
|
}
|
2016-04-23 06:00:52 +00:00
|
|
|
#undef Q_WINVER
|
2014-03-06 23:08:53 +00:00
|
|
|
// unknown, future version
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2014-03-06 23:22:27 +00:00
|
|
|
#if defined(Q_OS_UNIX)
|
2014-05-05 18:42:34 +00:00
|
|
|
# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD)
|
|
|
|
# define USE_ETC_OS_RELEASE
|
2014-03-06 23:08:53 +00:00
|
|
|
struct QUnixOSVersion
|
|
|
|
{
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
// from /etc/os-release older /etc/lsb-release // redhat /etc/redhat-release // debian /etc/debian_version
|
|
|
|
QString productType; // $ID $DISTRIB_ID // single line file containing: // Debian
|
|
|
|
QString productVersion; // $VERSION_ID $DISTRIB_RELEASE // <Vendor_ID release Version_ID> // single line file <Release_ID/sid>
|
2015-02-20 05:23:55 +00:00
|
|
|
QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION
|
2014-03-06 23:08:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static QString unquote(const char *begin, const char *end)
|
|
|
|
{
|
|
|
|
if (*begin == '"') {
|
|
|
|
Q_ASSERT(end[-1] == '"');
|
|
|
|
return QString::fromLatin1(begin + 1, end - begin - 2);
|
|
|
|
}
|
|
|
|
return QString::fromLatin1(begin, end - begin);
|
|
|
|
}
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
static QByteArray getEtcFileContent(const char *filename)
|
2014-03-06 23:08:53 +00:00
|
|
|
{
|
|
|
|
// we're avoiding QFile here
|
2015-02-20 05:23:55 +00:00
|
|
|
int fd = qt_safe_open(filename, O_RDONLY);
|
2014-05-05 18:42:34 +00:00
|
|
|
if (fd == -1)
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
return QByteArray();
|
2014-03-06 23:08:53 +00:00
|
|
|
|
|
|
|
QT_STATBUF sbuf;
|
|
|
|
if (QT_FSTAT(fd, &sbuf) == -1) {
|
|
|
|
qt_safe_close(fd);
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
return QByteArray();
|
2014-03-06 23:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray buffer(sbuf.st_size, Qt::Uninitialized);
|
|
|
|
buffer.resize(qt_safe_read(fd, buffer.data(), sbuf.st_size));
|
|
|
|
qt_safe_close(fd);
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool readEtcFile(QUnixOSVersion &v, const char *filename,
|
|
|
|
const QByteArray &idKey, const QByteArray &versionKey, const QByteArray &prettyNameKey)
|
|
|
|
{
|
|
|
|
|
|
|
|
QByteArray buffer = getEtcFileContent(filename);
|
|
|
|
if (buffer.isEmpty())
|
|
|
|
return false;
|
2014-03-06 23:08:53 +00:00
|
|
|
|
|
|
|
const char *ptr = buffer.constData();
|
|
|
|
const char *end = buffer.constEnd();
|
|
|
|
const char *eol;
|
2015-02-20 05:23:55 +00:00
|
|
|
QByteArray line;
|
2014-03-06 23:08:53 +00:00
|
|
|
for ( ; ptr != end; ptr = eol + 1) {
|
|
|
|
// find the end of the line after ptr
|
|
|
|
eol = static_cast<const char *>(memchr(ptr, '\n', end - ptr));
|
|
|
|
if (!eol)
|
|
|
|
eol = end - 1;
|
2015-02-20 05:23:55 +00:00
|
|
|
line.setRawData(ptr, eol - ptr);
|
2014-03-06 23:08:53 +00:00
|
|
|
|
2015-02-20 05:23:55 +00:00
|
|
|
if (line.startsWith(idKey)) {
|
|
|
|
ptr += idKey.length();
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
v.productType = unquote(ptr, eol);
|
2014-03-06 23:08:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-02-20 05:23:55 +00:00
|
|
|
if (line.startsWith(prettyNameKey)) {
|
|
|
|
ptr += prettyNameKey.length();
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
v.prettyName = unquote(ptr, eol);
|
2014-03-06 23:08:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-02-20 05:23:55 +00:00
|
|
|
if (line.startsWith(versionKey)) {
|
|
|
|
ptr += versionKey.length();
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
v.productVersion = unquote(ptr, eol);
|
2014-03-06 23:08:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-05-05 18:42:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-20 05:23:55 +00:00
|
|
|
|
|
|
|
static bool readEtcOsRelease(QUnixOSVersion &v)
|
|
|
|
{
|
|
|
|
return readEtcFile(v, "/etc/os-release", QByteArrayLiteral("ID="),
|
|
|
|
QByteArrayLiteral("VERSION_ID="), QByteArrayLiteral("PRETTY_NAME="));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool readEtcLsbRelease(QUnixOSVersion &v)
|
|
|
|
{
|
|
|
|
bool ok = readEtcFile(v, "/etc/lsb-release", QByteArrayLiteral("DISTRIB_ID="),
|
|
|
|
QByteArrayLiteral("DISTRIB_RELEASE="), QByteArrayLiteral("DISTRIB_DESCRIPTION="));
|
|
|
|
if (ok && (v.prettyName.isEmpty() || v.prettyName == v.productType)) {
|
|
|
|
// some distributions have redundant information for the pretty name,
|
|
|
|
// so try /etc/<lowercasename>-release
|
|
|
|
|
|
|
|
// we're still avoiding QFile here
|
|
|
|
QByteArray distrorelease = "/etc/" + v.productType.toLatin1().toLower() + "-release";
|
|
|
|
int fd = qt_safe_open(distrorelease, O_RDONLY);
|
|
|
|
if (fd != -1) {
|
|
|
|
QT_STATBUF sbuf;
|
|
|
|
if (QT_FSTAT(fd, &sbuf) != -1 && sbuf.st_size > v.prettyName.length()) {
|
|
|
|
// file apparently contains interesting information
|
|
|
|
QByteArray buffer(sbuf.st_size, Qt::Uninitialized);
|
|
|
|
buffer.resize(qt_safe_read(fd, buffer.data(), sbuf.st_size));
|
|
|
|
v.prettyName = QString::fromLatin1(buffer.trimmed());
|
|
|
|
}
|
|
|
|
qt_safe_close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
// some distributions have a /etc/lsb-release file that does not provide the values
|
|
|
|
// we are looking for, i.e. DISTRIB_ID, DISTRIB_RELEASE and DISTRIB_DESCRIPTION.
|
|
|
|
// Assuming that neither DISTRIB_ID nor DISTRIB_RELEASE were found, or contained valid values,
|
|
|
|
// returning false for readEtcLsbRelease will allow further /etc/<lowercasename>-release parsing.
|
|
|
|
return ok && !(v.productType.isEmpty() && v.productVersion.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
static QByteArray getEtcFileFirstLine(const char *fileName)
|
|
|
|
{
|
|
|
|
QByteArray buffer = getEtcFileContent(fileName);
|
|
|
|
if (buffer.isEmpty())
|
|
|
|
return QByteArray();
|
|
|
|
|
|
|
|
const char *ptr = buffer.constData();
|
|
|
|
int eol = buffer.indexOf("\n");
|
|
|
|
return QByteArray(ptr, eol).trimmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool readEtcRedHatRelease(QUnixOSVersion &v)
|
|
|
|
{
|
|
|
|
// /etc/redhat-release analysed should be a one line file
|
|
|
|
// the format of its content is <Vendor_ID release Version>
|
|
|
|
// i.e. "Red Hat Enterprise Linux Workstation release 6.5 (Santiago)"
|
|
|
|
QByteArray line = getEtcFileFirstLine("/etc/redhat-release");
|
|
|
|
if (line.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
v.prettyName = QString::fromLatin1(line);
|
|
|
|
|
|
|
|
const char keyword[] = "release ";
|
|
|
|
int releaseIndex = line.indexOf(keyword);
|
|
|
|
v.productType = QString::fromLatin1(line.mid(0, releaseIndex)).remove(QLatin1Char(' '));
|
|
|
|
int spaceIndex = line.indexOf(' ', releaseIndex + strlen(keyword));
|
2015-06-25 15:48:09 +00:00
|
|
|
v.productVersion = QString::fromLatin1(line.mid(releaseIndex + strlen(keyword),
|
|
|
|
spaceIndex > -1 ? spaceIndex - releaseIndex - int(strlen(keyword)) : -1));
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool readEtcDebianVersion(QUnixOSVersion &v)
|
|
|
|
{
|
|
|
|
// /etc/debian_version analysed should be a one line file
|
|
|
|
// the format of its content is <Release_ID/sid>
|
|
|
|
// i.e. "jessie/sid"
|
|
|
|
QByteArray line = getEtcFileFirstLine("/etc/debian_version");
|
|
|
|
if (line.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
v.productType = QStringLiteral("Debian");
|
|
|
|
v.productVersion = QString::fromLatin1(line);
|
|
|
|
return true;
|
2015-02-20 05:23:55 +00:00
|
|
|
}
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
#endif
|
2015-02-20 05:23:55 +00:00
|
|
|
|
|
|
|
static bool findUnixOsVersion(QUnixOSVersion &v)
|
|
|
|
{
|
|
|
|
if (readEtcOsRelease(v))
|
|
|
|
return true;
|
QSysInfo: Expand Linux distribution detection
Expand Linux distribution detection to /etc/redhat-release and
/etc/debian_version to follow what /usr/bin/lsb_release script does.
If /usr/bin/lsb_release fails to extract the distribution information
from /etc/lsb-release, it then checks /etc/redhat-release and, as a last
fallback, /etc/debian_version.
Some Red Hat distributions have a /etc/lsb-release file that
does not provide the values we are looking for (DISTRIB_ID,
DISTRIB_RELEASE and DISTRIB_DESCRIPTION).
If both productType or productVersion are empty after reading
/etc/lsb-release, readEtcLsbRelease() will return false, allowing
further parsing of /etc/redhat-release. This scenario mimics what
the /usr/bin/lsb_release script does if /etc/lsb-release does not
contains enough information.
The productType and productVersion returned by QSysInfo after reading
/etc/redhat-release match the distributor id and release information
returned by the /usr/bin/lsb_release script.
For Debian Linux distributions where /etc/os-release, /etc/lsb-release
and /etc/redhat-release are not available nor usable, the
/usr/bin/lsb_release script also checks for the /etc/debian_version
file.
In this case, we also enable parsing of /etc/debian_version to retrieve a
fallback productVersion, the productType being set to Debian.
Change-Id: Ia20d513d78be8a8ee8c0410d0aaa052fde81a41d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-04-15 11:26:55 +00:00
|
|
|
if (readEtcLsbRelease(v))
|
|
|
|
return true;
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
if (readEtcRedHatRelease(v))
|
|
|
|
return true;
|
|
|
|
if (readEtcDebianVersion(v))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
2015-02-20 05:23:55 +00:00
|
|
|
}
|
2014-05-05 18:42:34 +00:00
|
|
|
# endif // USE_ETC_OS_RELEASE
|
|
|
|
#endif // Q_OS_UNIX
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-04-24 11:07:23 +00:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
static const char *osVer_helper(QOperatingSystemVersion)
|
|
|
|
{
|
|
|
|
/* Data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cupcake
|
|
|
|
Donut
|
|
|
|
Eclair
|
|
|
|
Eclair
|
|
|
|
Eclair
|
|
|
|
Froyo
|
|
|
|
Gingerbread
|
|
|
|
Gingerbread
|
|
|
|
Honeycomb
|
|
|
|
Honeycomb
|
|
|
|
Honeycomb
|
|
|
|
Ice Cream Sandwich
|
|
|
|
Ice Cream Sandwich
|
|
|
|
Jelly Bean
|
|
|
|
Jelly Bean
|
|
|
|
Jelly Bean
|
|
|
|
KitKat
|
|
|
|
KitKat
|
|
|
|
Lollipop
|
|
|
|
Lollipop
|
|
|
|
Marshmallow
|
2016-10-27 18:06:51 +00:00
|
|
|
Nougat
|
2016-04-24 11:07:23 +00:00
|
|
|
Nougat
|
|
|
|
*/
|
|
|
|
static const char versions_string[] =
|
|
|
|
"\0"
|
|
|
|
"Cupcake\0"
|
|
|
|
"Donut\0"
|
|
|
|
"Eclair\0"
|
|
|
|
"Froyo\0"
|
|
|
|
"Gingerbread\0"
|
|
|
|
"Honeycomb\0"
|
|
|
|
"Ice Cream Sandwich\0"
|
|
|
|
"Jelly Bean\0"
|
|
|
|
"KitKat\0"
|
|
|
|
"Lollipop\0"
|
|
|
|
"Marshmallow\0"
|
|
|
|
"Nougat\0"
|
|
|
|
"\0";
|
|
|
|
|
|
|
|
static const int versions_indices[] = {
|
|
|
|
0, 0, 0, 1, 9, 15, 15, 15,
|
|
|
|
22, 28, 28, 40, 40, 40, 50, 50,
|
|
|
|
69, 69, 69, 80, 80, 87, 87, 96,
|
2016-10-27 18:06:51 +00:00
|
|
|
108, 108, -1
|
2016-04-24 11:07:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int versions_count = (sizeof versions_indices) / (sizeof versions_indices[0]);
|
|
|
|
|
|
|
|
// https://source.android.com/source/build-numbers.html
|
|
|
|
// https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
|
|
|
|
const int sdk_int = QJNIObjectPrivate::getStaticField<jint>("android/os/Build$VERSION", "SDK_INT");
|
|
|
|
return &versions_string[versions_indices[qBound(0, sdk_int, versions_count - 1)]];
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-06 20:58:21 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns the architecture of the CPU that Qt was compiled for, in text
|
|
|
|
format. Note that this may not match the actual CPU that the application is
|
|
|
|
running on if there's an emulation layer or if the CPU supports multiple
|
2014-06-30 23:17:31 +00:00
|
|
|
architectures (like x86-64 processors supporting i386 applications). To
|
|
|
|
detect that, use currentCpuArchitecture().
|
2014-03-06 20:58:21 +00:00
|
|
|
|
|
|
|
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 CPU types may be added over time.
|
|
|
|
|
|
|
|
Typical returned values are (note: list not exhaustive):
|
|
|
|
\list
|
|
|
|
\li "arm"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "arm64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\li "i386"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "ia64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\li "mips"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "mips64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\li "power"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "power64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\li "sparc"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "sparcv9"
|
|
|
|
\li "x86_64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\endlist
|
|
|
|
|
2014-06-30 23:17:31 +00:00
|
|
|
\sa QSysInfo::buildAbi(), QSysInfo::currentCpuArchitecture()
|
2014-03-06 20:58:21 +00:00
|
|
|
*/
|
2014-07-05 22:15:55 +00:00
|
|
|
QString QSysInfo::buildCpuArchitecture()
|
2014-03-06 20:58:21 +00:00
|
|
|
{
|
|
|
|
return QStringLiteral(ARCH_PROCESSOR);
|
|
|
|
}
|
|
|
|
|
2014-06-30 23:17:31 +00:00
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns the architecture of the CPU that the application is running on, in
|
|
|
|
text format. Note that this function depends on what the OS will report and
|
|
|
|
may not detect the actual CPU architecture if the OS hides that information
|
|
|
|
or is unable to provide it. For example, a 32-bit OS running on a 64-bit
|
|
|
|
CPU is usually unable to determine the CPU is actually capable of running
|
|
|
|
64-bit programs.
|
|
|
|
|
|
|
|
Values returned by this function are mostly stable: an attempt will be made
|
|
|
|
to ensure that they stay constant over time and match the values returned
|
|
|
|
by QSysInfo::builldCpuArchitecture(). However, due to the nature of the
|
|
|
|
operating system functions being used, there may be discrepancies.
|
|
|
|
|
|
|
|
Typical returned values are (note: list not exhaustive):
|
|
|
|
\list
|
|
|
|
\li "arm"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "arm64"
|
2014-06-30 23:17:31 +00:00
|
|
|
\li "i386"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "ia64"
|
2014-06-30 23:17:31 +00:00
|
|
|
\li "mips"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "mips64"
|
2014-06-30 23:17:31 +00:00
|
|
|
\li "power"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "power64"
|
2014-06-30 23:17:31 +00:00
|
|
|
\li "sparc"
|
2014-07-07 21:07:10 +00:00
|
|
|
\li "sparcv9"
|
|
|
|
\li "x86_64"
|
2014-06-30 23:17:31 +00:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
\sa QSysInfo::buildAbi(), QSysInfo::buildCpuArchitecture()
|
|
|
|
*/
|
|
|
|
QString QSysInfo::currentCpuArchitecture()
|
|
|
|
{
|
2016-03-23 09:25:46 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2014-06-30 23:17:31 +00:00
|
|
|
// We don't need to catch all the CPU architectures in this function;
|
|
|
|
// only those where the host CPU might be different than the build target
|
|
|
|
// (usually, 64-bit platforms).
|
|
|
|
SYSTEM_INFO info;
|
|
|
|
GetNativeSystemInfo(&info);
|
|
|
|
switch (info.wProcessorArchitecture) {
|
|
|
|
# ifdef PROCESSOR_ARCHITECTURE_AMD64
|
|
|
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
|
|
|
return QStringLiteral("x86_64");
|
|
|
|
# endif
|
|
|
|
# ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
|
|
|
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
|
|
|
|
# endif
|
|
|
|
case PROCESSOR_ARCHITECTURE_IA64:
|
|
|
|
return QStringLiteral("ia64");
|
|
|
|
}
|
2017-06-05 17:52:02 +00:00
|
|
|
#elif defined(Q_OS_DARWIN) && !defined(Q_OS_MACOS)
|
|
|
|
// iOS-based OSes do not return the architecture on uname(2)'s result.
|
|
|
|
return buildCpuArchitecture();
|
2014-06-30 23:17:31 +00:00
|
|
|
#elif defined(Q_OS_UNIX)
|
2014-07-07 21:33:56 +00:00
|
|
|
long ret = -1;
|
2014-06-30 23:17:31 +00:00
|
|
|
struct utsname u;
|
2014-07-07 21:33:56 +00:00
|
|
|
|
|
|
|
# if defined(Q_OS_SOLARIS)
|
|
|
|
// We need a special call for Solaris because uname(2) on x86 returns "i86pc" for
|
|
|
|
// both 32- and 64-bit CPUs. Reference:
|
|
|
|
// http://docs.oracle.com/cd/E18752_01/html/816-5167/sysinfo-2.html#REFMAN2sysinfo-2
|
|
|
|
// http://fxr.watson.org/fxr/source/common/syscall/systeminfo.c?v=OPENSOLARIS
|
|
|
|
// http://fxr.watson.org/fxr/source/common/conf/param.c?v=OPENSOLARIS;im=10#L530
|
|
|
|
if (ret == -1)
|
|
|
|
ret = sysinfo(SI_ARCHITECTURE_64, u.machine, sizeof u.machine);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
ret = uname(&u);
|
|
|
|
|
|
|
|
// we could use detectUnixVersion() above, but we only need a field no other function does
|
|
|
|
if (ret != -1) {
|
2014-06-30 23:17:31 +00:00
|
|
|
// the use of QT_BUILD_INTERNAL here is simply to ensure all branches build
|
|
|
|
// as we don't often build on some of the less common platforms
|
|
|
|
# if defined(Q_PROCESSOR_ARM) || defined(QT_BUILD_INTERNAL)
|
|
|
|
if (strcmp(u.machine, "aarch64") == 0)
|
|
|
|
return QStringLiteral("arm64");
|
|
|
|
if (strncmp(u.machine, "armv", 4) == 0)
|
|
|
|
return QStringLiteral("arm");
|
|
|
|
# endif
|
|
|
|
# if defined(Q_PROCESSOR_POWER) || defined(QT_BUILD_INTERNAL)
|
|
|
|
// harmonize "powerpc" and "ppc" to "power"
|
|
|
|
if (strncmp(u.machine, "ppc", 3) == 0)
|
|
|
|
return QLatin1String("power") + QLatin1String(u.machine + 3);
|
|
|
|
if (strncmp(u.machine, "powerpc", 7) == 0)
|
|
|
|
return QLatin1String("power") + QLatin1String(u.machine + 7);
|
|
|
|
if (strcmp(u.machine, "Power Macintosh") == 0)
|
|
|
|
return QLatin1String("power");
|
|
|
|
# endif
|
|
|
|
# if defined(Q_PROCESSOR_SPARC) || defined(QT_BUILD_INTERNAL)
|
2014-07-07 21:33:56 +00:00
|
|
|
// Solaris sysinfo(2) (above) uses "sparcv9", but uname -m says "sun4u";
|
2014-06-30 23:17:31 +00:00
|
|
|
// Linux says "sparc64"
|
|
|
|
if (strcmp(u.machine, "sun4u") == 0 || strcmp(u.machine, "sparc64") == 0)
|
|
|
|
return QStringLiteral("sparcv9");
|
|
|
|
if (strcmp(u.machine, "sparc32") == 0)
|
|
|
|
return QStringLiteral("sparc");
|
|
|
|
# endif
|
|
|
|
# if defined(Q_PROCESSOR_X86) || defined(QT_BUILD_INTERNAL)
|
|
|
|
// harmonize all "i?86" to "i386"
|
|
|
|
if (strlen(u.machine) == 4 && u.machine[0] == 'i'
|
|
|
|
&& u.machine[2] == '8' && u.machine[3] == '6')
|
|
|
|
return QStringLiteral("i386");
|
2014-07-07 21:33:56 +00:00
|
|
|
if (strcmp(u.machine, "amd64") == 0) // Solaris
|
|
|
|
return QStringLiteral("x86_64");
|
2014-06-30 23:17:31 +00:00
|
|
|
# endif
|
|
|
|
return QString::fromLatin1(u.machine);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return buildCpuArchitecture();
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:58:21 +00:00
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns the full architecture string that Qt was compiled for. This string
|
|
|
|
is useful for identifying different, incompatible builds. For example, it
|
|
|
|
can be used as an identifier to request an upgrade package from a server.
|
|
|
|
|
|
|
|
The values returned from this function are kept stable as follows: the
|
|
|
|
mandatory components of the result will not change in future versions of
|
|
|
|
Qt, but optional suffixes may be added.
|
|
|
|
|
|
|
|
The returned value is composed of three or more parts, separated by dashes
|
|
|
|
("-"). They are:
|
|
|
|
|
|
|
|
\table
|
|
|
|
\header \li Component \li Value
|
2014-07-05 22:15:55 +00:00
|
|
|
\row \li CPU Architecture \li The same as QSysInfo::buildCpuArchitecture(), such as "arm", "i386", "mips" or "x86_64"
|
2014-03-06 20:58:21 +00:00
|
|
|
\row \li Endianness \li "little_endian" or "big_endian"
|
|
|
|
\row \li Word size \li Whether it's a 32- or 64-bit application. Possible values are:
|
|
|
|
"llp64" (Windows 64-bit), "lp64" (Unix 64-bit), "ilp32" (32-bit)
|
|
|
|
\row \li (Optional) ABI \li Zero or more components identifying different ABIs possible in this architecture.
|
|
|
|
Currently, Qt has optional ABI components for ARM and MIPS processors: one
|
|
|
|
component is the main ABI (such as "eabi", "o32", "n32", "o64"); another is
|
|
|
|
whether the calling convention is using hardware floating point registers ("hardfloat"
|
|
|
|
is present).
|
2014-06-13 22:12:28 +00:00
|
|
|
|
|
|
|
Additionally, if Qt was configured with \c{-qreal float}, the ABI option tag "qreal_float"
|
|
|
|
will be present. If Qt was configured with another type as qreal, that type is present after
|
|
|
|
"qreal_", with all characters other than letters and digits escaped by an underscore, followed
|
|
|
|
by two hex digits. For example, \c{-qreal long double} becomes "qreal_long_20double".
|
2014-03-06 20:58:21 +00:00
|
|
|
\endtable
|
|
|
|
|
2014-07-05 22:15:55 +00:00
|
|
|
\sa QSysInfo::buildCpuArchitecture()
|
2014-03-06 20:58:21 +00:00
|
|
|
*/
|
2014-07-05 22:15:55 +00:00
|
|
|
QString QSysInfo::buildAbi()
|
2014-03-06 20:58:21 +00:00
|
|
|
{
|
|
|
|
#ifdef Q_COMPILER_UNICODE_STRINGS
|
|
|
|
// ARCH_FULL is a concatenation of strings (incl. ARCH_PROCESSOR), which breaks
|
|
|
|
// QStringLiteral on MSVC. Since the concatenation behavior we want is specified
|
|
|
|
// the same C++11 paper as the Unicode strings, we'll use that macro and hope
|
|
|
|
// that Microsoft implements the new behavior when they add support for Unicode strings.
|
|
|
|
return QStringLiteral(ARCH_FULL);
|
|
|
|
#else
|
|
|
|
return QLatin1String(ARCH_FULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:08:53 +00:00
|
|
|
static QString unknownText()
|
|
|
|
{
|
|
|
|
return QStringLiteral("unknown");
|
|
|
|
}
|
|
|
|
|
2014-03-06 21:32:31 +00:00
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
Returns the type of the operating system kernel Qt was compiled for. It's
|
|
|
|
also the kernel the application is running on, unless the host operating
|
|
|
|
system is running a form of compatibility or virtualization 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 kernel types may be added over time.
|
|
|
|
|
2016-08-16 14:44:02 +00:00
|
|
|
On Windows, this function returns the type of Windows kernel, like "winnt".
|
|
|
|
On Unix systems, it returns the same as the output of \c{uname
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
-s} (lowercased).
|
|
|
|
|
2016-08-16 14:44:02 +00:00
|
|
|
\note This function may return surprising values: it returns "linux"
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
for all operating systems running Linux (including Android), "qnx" for all
|
2015-10-15 13:24:54 +00:00
|
|
|
operating systems running QNX, "freebsd" for
|
2016-08-03 10:00:41 +00:00
|
|
|
Debian/kFreeBSD, and "darwin" for \macos and iOS. For information on the type
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
of product the application is running on, see productType().
|
|
|
|
|
|
|
|
\sa QFileSelector, kernelVersion(), productType(), productVersion(), prettyProductName()
|
|
|
|
*/
|
|
|
|
QString QSysInfo::kernelType()
|
|
|
|
{
|
2016-03-23 09:25:46 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
return QStringLiteral("winnt");
|
|
|
|
#elif defined(Q_OS_UNIX)
|
2014-07-08 04:27:46 +00:00
|
|
|
struct utsname u;
|
|
|
|
if (uname(&u) == 0)
|
|
|
|
return QString::fromLatin1(u.sysname).toLower();
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
#endif
|
|
|
|
return unknownText();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns the release version of the operating system kernel. On Windows, it
|
2016-06-15 23:23:52 +00:00
|
|
|
returns the version of the NT kernel. On Unix systems, including
|
2016-08-12 23:05:02 +00:00
|
|
|
Android and \macos, it returns the same as the \c{uname -r}
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
command would return.
|
|
|
|
|
|
|
|
If the version could not be determined, this function may return an empty
|
|
|
|
string.
|
|
|
|
|
|
|
|
\sa kernelType(), productType(), productVersion(), prettyProductName()
|
|
|
|
*/
|
|
|
|
QString QSysInfo::kernelVersion()
|
|
|
|
{
|
2015-08-19 00:23:56 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto osver = QOperatingSystemVersion::current();
|
|
|
|
return QString::number(osver.majorVersion()) + QLatin1Char('.') + QString::number(osver.minorVersion())
|
|
|
|
+ QLatin1Char('.') + QString::number(osver.microVersion());
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
#else
|
2014-07-08 04:27:46 +00:00
|
|
|
struct utsname u;
|
|
|
|
if (uname(&u) == 0)
|
|
|
|
return QString::fromLatin1(u.release);
|
|
|
|
return QString();
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns the product name of the operating system this application is
|
|
|
|
running in. If the application is running on some sort of emulation or
|
|
|
|
virtualization layer (such as WINE on a Unix system), this function will
|
|
|
|
inspect the emulation / virtualization layer.
|
2014-03-06 21:32:31 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
\b{Linux and 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 tries
|
|
|
|
to determine the distribution name and returns that. If determining the
|
|
|
|
distribution name failed, it returns "unknown".
|
2014-03-06 21:32:31 +00:00
|
|
|
|
2017-04-06 04:11:12 +00:00
|
|
|
\b{\macos note}: this function returns "osx" for all \macos systems,
|
|
|
|
regardless of Apple naming convention. The returned string will be updated
|
|
|
|
for Qt 6. Note that this function erroneously returned "macos" for \macos
|
|
|
|
10.12 in Qt versions 5.6.2, 5.7.1, and 5.8.0.
|
2014-03-06 21:32:31 +00:00
|
|
|
|
2017-04-06 04:11:12 +00:00
|
|
|
\b{Darwin, iOS, tvOS, and watchOS note}: this function returns "ios" for
|
|
|
|
iOS systems, "tvos" for tvOS systems, "watchos" for watchOS systems, and
|
|
|
|
"darwin" in case the system could not be determined.
|
2016-06-11 04:13:35 +00:00
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
\b{FreeBSD note}: this function returns "debian" for Debian/kFreeBSD and
|
|
|
|
"unknown" otherwise.
|
|
|
|
|
2016-11-22 13:54:02 +00:00
|
|
|
\b{Windows note}: this function "winrt" for WinRT builds, and "windows"
|
|
|
|
for normal desktop builds.
|
2014-03-06 21:32:31 +00:00
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
For other Unix-type systems, this function usually returns "unknown".
|
|
|
|
|
|
|
|
\sa QFileSelector, kernelType(), kernelVersion(), productVersion(), prettyProductName()
|
2014-03-06 21:32:31 +00:00
|
|
|
*/
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
QString QSysInfo::productType()
|
2014-03-06 21:32:31 +00:00
|
|
|
{
|
|
|
|
// similar, but not identical to QFileSelectorPrivate::platformSelectors
|
2016-11-22 13:54:02 +00:00
|
|
|
#if defined(Q_OS_WINRT)
|
2014-03-06 21:32:31 +00:00
|
|
|
return QStringLiteral("winrt");
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
return QStringLiteral("windows");
|
|
|
|
|
|
|
|
#elif defined(Q_OS_QNX)
|
|
|
|
return QStringLiteral("qnx");
|
|
|
|
|
|
|
|
#elif defined(Q_OS_ANDROID)
|
|
|
|
return QStringLiteral("android");
|
|
|
|
|
|
|
|
#elif defined(Q_OS_IOS)
|
|
|
|
return QStringLiteral("ios");
|
2016-02-16 14:29:59 +00:00
|
|
|
#elif defined(Q_OS_TVOS)
|
|
|
|
return QStringLiteral("tvos");
|
2016-05-20 06:01:59 +00:00
|
|
|
#elif defined(Q_OS_WATCHOS)
|
|
|
|
return QStringLiteral("watchos");
|
2016-06-11 04:13:35 +00:00
|
|
|
#elif defined(Q_OS_MACOS)
|
2017-04-06 04:11:12 +00:00
|
|
|
// ### Qt6: remove fallback
|
|
|
|
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2016-06-11 04:13:35 +00:00
|
|
|
return QStringLiteral("macos");
|
2017-04-06 04:11:12 +00:00
|
|
|
# else
|
|
|
|
return QStringLiteral("osx");
|
|
|
|
# endif
|
2014-03-06 21:32:31 +00:00
|
|
|
#elif defined(Q_OS_DARWIN)
|
|
|
|
return QStringLiteral("darwin");
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
|
2014-07-08 04:27:46 +00:00
|
|
|
QUnixOSVersion unixOsVersion;
|
2015-02-20 05:23:55 +00:00
|
|
|
findUnixOsVersion(unixOsVersion);
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
if (!unixOsVersion.productType.isEmpty())
|
|
|
|
return unixOsVersion.productType;
|
2014-03-06 21:32:31 +00:00
|
|
|
#endif
|
2014-03-06 23:08:53 +00:00
|
|
|
return unknownText();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
Returns the product version of the operating system in string form. If the
|
|
|
|
version could not be determined, this function returns "unknown".
|
2014-03-06 23:08:53 +00:00
|
|
|
|
2016-08-12 23:05:02 +00:00
|
|
|
It will return the Android, iOS, \macos, Windows full-product
|
2016-12-05 22:07:47 +00:00
|
|
|
versions on those systems.
|
|
|
|
|
|
|
|
Typical returned values are (note: list not exhaustive):
|
|
|
|
\list
|
|
|
|
\li "2016.09" (Amazon Linux AMI 2016.09)
|
|
|
|
\li "7.1" (Android Nougat)
|
|
|
|
\li "25" (Fedora 25)
|
|
|
|
\li "10.1" (iOS 10.1)
|
|
|
|
\li "10.12" (macOS Sierra)
|
|
|
|
\li "10.0" (tvOS 10)
|
|
|
|
\li "16.10" (Ubuntu 16.10)
|
|
|
|
\li "3.1" (watchOS 3.1)
|
|
|
|
\li "7 SP 1" (Windows 7 Service Pack 1)
|
|
|
|
\li "8.1" (Windows 8.1)
|
|
|
|
\li "10" (Windows 10)
|
|
|
|
\li "Server 2016" (Windows Server 2016)
|
|
|
|
\endlist
|
2014-03-06 23:08:53 +00:00
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
On Linux systems, it will try to determine the distribution version and will
|
|
|
|
return that. This is also done on Debian/kFreeBSD, so this function will
|
|
|
|
return Debian version in that case.
|
|
|
|
|
|
|
|
In all other Unix-type systems, this function always returns "unknown".
|
|
|
|
|
2016-06-15 23:23:52 +00:00
|
|
|
\note The version string returned from this function is not guaranteed to
|
|
|
|
be orderable. On Linux, the version of
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
the distribution may jump unexpectedly, please refer to the distribution's
|
|
|
|
documentation for versioning practices.
|
|
|
|
|
|
|
|
\sa kernelType(), kernelVersion(), productType(), prettyProductName()
|
2014-03-06 23:08:53 +00:00
|
|
|
*/
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
QString QSysInfo::productVersion()
|
2014-03-06 23:08:53 +00:00
|
|
|
{
|
2016-09-09 17:01:58 +00:00
|
|
|
#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto version = QOperatingSystemVersion::current();
|
|
|
|
return QString::number(version.majorVersion()) + QLatin1Char('.') + QString::number(version.minorVersion());
|
2014-03-06 23:08:53 +00:00
|
|
|
#elif defined(Q_OS_WIN)
|
2016-04-23 03:54:51 +00:00
|
|
|
const char *version = osVer_helper();
|
2015-12-08 08:08:31 +00:00
|
|
|
if (version) {
|
|
|
|
const QLatin1Char spaceChar(' ');
|
|
|
|
return QString::fromLatin1(version).remove(spaceChar).toLower() + winSp_helper().remove(spaceChar).toLower();
|
|
|
|
}
|
2014-03-06 23:08:53 +00:00
|
|
|
// fall through
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
|
2014-07-08 04:27:46 +00:00
|
|
|
QUnixOSVersion unixOsVersion;
|
2015-02-20 05:23:55 +00:00
|
|
|
findUnixOsVersion(unixOsVersion);
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
if (!unixOsVersion.productVersion.isEmpty())
|
|
|
|
return unixOsVersion.productVersion;
|
2014-03-06 23:08:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// fallback
|
|
|
|
return unknownText();
|
2014-03-06 21:32:31 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:08:53 +00:00
|
|
|
/*!
|
|
|
|
\since 5.4
|
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
Returns a prettier form of productType() and productVersion(), containing
|
|
|
|
other tokens like the operating system type, codenames and other
|
|
|
|
information. The result of this function is suitable for displaying to the
|
|
|
|
user, but not for long-term storage, as the string may change with updates
|
|
|
|
to Qt.
|
|
|
|
|
|
|
|
If productType() is "unknown", this function will instead use the
|
|
|
|
kernelType() and kernelVersion() functions.
|
2014-03-06 23:08:53 +00:00
|
|
|
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
\sa kernelType(), kernelVersion(), productType(), productVersion()
|
2014-03-06 23:08:53 +00:00
|
|
|
*/
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
QString QSysInfo::prettyProductName()
|
2014-03-06 23:08:53 +00:00
|
|
|
{
|
2016-11-22 13:54:02 +00:00
|
|
|
#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN) || defined(Q_OS_WIN)
|
2016-04-23 03:54:51 +00:00
|
|
|
const auto version = QOperatingSystemVersion::current();
|
|
|
|
const char *name = osVer_helper(version);
|
2016-04-23 06:00:05 +00:00
|
|
|
if (name)
|
2016-04-23 03:54:51 +00:00
|
|
|
return version.name() + QLatin1Char(' ') + QLatin1String(name)
|
|
|
|
# if defined(Q_OS_WIN)
|
|
|
|
+ winSp_helper()
|
|
|
|
# endif
|
|
|
|
+ QLatin1String(" (") + QString::number(version.majorVersion())
|
|
|
|
+ QLatin1Char('.') + QString::number(version.minorVersion())
|
2016-04-23 06:00:05 +00:00
|
|
|
+ QLatin1Char(')');
|
2016-04-23 03:54:51 +00:00
|
|
|
else
|
|
|
|
return version.name() + QLatin1Char(' ')
|
|
|
|
+ QString::number(version.majorVersion()) + QLatin1Char('.')
|
|
|
|
+ QString::number(version.minorVersion());
|
2014-12-16 11:08:37 +00:00
|
|
|
#elif defined(Q_OS_HAIKU)
|
|
|
|
return QLatin1String("Haiku ") + productVersion();
|
2014-03-06 23:08:53 +00:00
|
|
|
#elif defined(Q_OS_UNIX)
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
# ifdef USE_ETC_OS_RELEASE
|
2014-07-08 04:27:46 +00:00
|
|
|
QUnixOSVersion unixOsVersion;
|
2015-02-20 05:23:55 +00:00
|
|
|
findUnixOsVersion(unixOsVersion);
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
if (!unixOsVersion.prettyName.isEmpty())
|
|
|
|
return unixOsVersion.prettyName;
|
|
|
|
# endif
|
2014-07-08 04:27:46 +00:00
|
|
|
struct utsname u;
|
|
|
|
if (uname(&u) == 0)
|
|
|
|
return QString::fromLatin1(u.sysname) + QLatin1Char(' ') + QString::fromLatin1(u.release);
|
2014-03-06 23:22:27 +00:00
|
|
|
#endif
|
Rework of QSysInfo OS and kernel version functions
This patch splits the OS product from the kernel name and versions.
Previously, it was a little confusing.
Thus, osType is split in two: kernelType() always returns the kernel
type, which includes "linux" for Android, "darwin" for iOS and OS X,
"qnx" for BlackBerry, and "windows" for all the Windows OSes. The Linux
distribution name and the visible product names are found in
productType(), with the respective versions in productVersion().
For an update system, applications probably want to send all four
tokens:
- for Android, BlackBerry, iOS, OS X and Windows, the relevant
information is productType and productVersion
- for Linux distributions, in addition to productType and
productVersion, the kernelType ("linux") is useful as a fallback and
it's important for Debian/kFreeBSD and Debian/GNU
- for other Unix systems, the relevant information is kernelType and
kernelVersion
Change-Id: I66c36d5a4ddfad47babfc6744d752273705e7076
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
2014-07-08 02:28:34 +00:00
|
|
|
return unknownText();
|
2014-03-06 23:22:27 +00:00
|
|
|
}
|
2014-03-06 23:08:53 +00:00
|
|
|
|
2015-04-08 21:14:16 +00:00
|
|
|
#ifndef QT_BOOTSTRAPPED
|
|
|
|
/*!
|
|
|
|
\since 5.6
|
|
|
|
|
|
|
|
Returns this machine's host name, if one is configured. Note that hostnames
|
|
|
|
are not guaranteed to be globally unique, especially if they were
|
|
|
|
configured automatically.
|
|
|
|
|
|
|
|
This function does not guarantee the returned host name is a Fully
|
|
|
|
Qualified Domain Name (FQDN). For that, use QHostInfo to resolve the
|
|
|
|
returned name to an FQDN.
|
|
|
|
|
|
|
|
This function returns the same as QHostInfo::localHostName().
|
|
|
|
|
|
|
|
\sa QHostInfo::localDomainName
|
|
|
|
*/
|
|
|
|
QString QSysInfo::machineHostName()
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
// gethostname(3) on Linux just calls uname(2), so do it ourselves
|
|
|
|
// and avoid a memcpy
|
|
|
|
struct utsname u;
|
|
|
|
if (uname(&u) == 0)
|
|
|
|
return QString::fromLocal8Bit(u.nodename);
|
|
|
|
#else
|
|
|
|
# ifdef Q_OS_WIN
|
|
|
|
// Important: QtNetwork depends on machineHostName() initializing ws2_32.dll
|
|
|
|
winsockInit();
|
|
|
|
# endif
|
|
|
|
|
|
|
|
char hostName[512];
|
|
|
|
if (gethostname(hostName, sizeof(hostName)) == -1)
|
|
|
|
return QString();
|
|
|
|
hostName[sizeof(hostName) - 1] = '\0';
|
|
|
|
return QString::fromLocal8Bit(hostName);
|
|
|
|
#endif
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
#endif // QT_BOOTSTRAPPED
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro void Q_ASSERT(bool test)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Prints a warning message containing the source code file name and
|
2014-01-27 14:20:25 +00:00
|
|
|
line number if \a test is \c false.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Q_ASSERT() is useful for testing pre- and post-conditions
|
|
|
|
during development. It does nothing if \c QT_NO_DEBUG was defined
|
|
|
|
during compilation.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 17
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If \c b is zero, the Q_ASSERT statement will output the following
|
|
|
|
message using the qFatal() function:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 18
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro void Q_ASSERT_X(bool test, const char *where, const char *what)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Prints the message \a what together with the location \a where,
|
2014-01-27 14:20:25 +00:00
|
|
|
the source file name and line number if \a test is \c false.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Q_ASSERT_X is useful for testing pre- and post-conditions during
|
|
|
|
development. It does nothing if \c QT_NO_DEBUG was defined during
|
|
|
|
compilation.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 19
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If \c b is zero, the Q_ASSERT_X statement will output the following
|
|
|
|
message using the qFatal() function:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 20
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_ASSERT(), qFatal(), {Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
2011-12-31 02:15:06 +00:00
|
|
|
/*!
|
|
|
|
\macro void Q_ASSUME(bool expr)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.0
|
|
|
|
|
2014-01-27 14:20:25 +00:00
|
|
|
Causes the compiler to assume that \a expr is \c true. This macro is useful
|
2011-12-31 02:15:06 +00:00
|
|
|
for improving code generation, by providing the compiler with hints about
|
|
|
|
conditions that it would not otherwise know about. However, there is no
|
|
|
|
guarantee that the compiler will actually use those hints.
|
|
|
|
|
2014-02-01 15:30:08 +00:00
|
|
|
This macro could be considered a "lighter" version of \l{Q_ASSERT()}. While
|
2014-01-27 14:20:25 +00:00
|
|
|
Q_ASSERT will abort the program's execution if the condition is \c false,
|
2011-12-31 02:15:06 +00:00
|
|
|
Q_ASSUME will tell the compiler not to generate code for those conditions.
|
|
|
|
Therefore, it is important that the assumptions always hold, otherwise
|
|
|
|
undefined behaviour may occur.
|
|
|
|
|
2014-01-27 14:20:25 +00:00
|
|
|
If \a expr is a constantly \c false condition, Q_ASSUME will tell the compiler
|
2011-12-31 02:15:06 +00:00
|
|
|
that the current code execution cannot be reached. That is, Q_ASSUME(false)
|
|
|
|
is equivalent to Q_UNREACHABLE().
|
|
|
|
|
2013-01-10 09:05:02 +00:00
|
|
|
In debug builds the condition is enforced by an assert to facilitate debugging.
|
|
|
|
|
2011-12-31 02:15:06 +00:00
|
|
|
\note Q_LIKELY() tells the compiler that the expression is likely, but not
|
|
|
|
the only possibility. Q_ASSUME tells the compiler that it is the only
|
|
|
|
possibility.
|
|
|
|
|
|
|
|
\sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro void Q_UNREACHABLE()
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.0
|
|
|
|
|
|
|
|
Tells the compiler that the current point cannot be reached by any
|
2012-07-11 12:44:38 +00:00
|
|
|
execution, so it may optimize any code paths leading here as dead code, as
|
2011-12-31 02:15:06 +00:00
|
|
|
well as code continuing from here.
|
|
|
|
|
|
|
|
This macro is useful to mark impossible conditions. For example, given the
|
|
|
|
following enum:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qunreachable-enum
|
2011-12-31 02:15:06 +00:00
|
|
|
|
|
|
|
One can write a switch table like so:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qunreachable-switch
|
2011-12-31 02:15:06 +00:00
|
|
|
|
|
|
|
The advantage of inserting Q_UNREACHABLE() at that point is that the
|
|
|
|
compiler is told not to generate code for a shape variable containing that
|
|
|
|
value. If the macro is missing, the compiler will still generate the
|
|
|
|
necessary comparisons for that value. If the case label were removed, some
|
|
|
|
compilers could produce a warning that some enum values were not checked.
|
|
|
|
|
|
|
|
By using this macro in impossible conditions, code coverage may be improved
|
|
|
|
as dead code paths may be eliminated.
|
|
|
|
|
2013-01-10 09:05:02 +00:00
|
|
|
In debug builds the condition is enforced by an assert to facilitate debugging.
|
|
|
|
|
2011-12-31 02:15:06 +00:00
|
|
|
\sa Q_ASSERT(), Q_ASSUME(), qFatal()
|
|
|
|
*/
|
|
|
|
|
2016-06-27 13:43:33 +00:00
|
|
|
/*!
|
|
|
|
\macro void Q_FALLTHROUGH()
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.8
|
|
|
|
|
|
|
|
Can be used in switch statements at the end of case block to tell the compiler
|
|
|
|
and other developers that that the lack of a break statement is intentional.
|
|
|
|
|
|
|
|
This is useful since a missing break statement is often a bug, and some
|
|
|
|
compilers can be configured to emit warnings when one is not found.
|
|
|
|
|
|
|
|
\sa Q_UNREACHABLE()
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro void Q_CHECK_PTR(void *pointer)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2015-02-25 10:05:29 +00:00
|
|
|
If \a pointer is 0, prints a message containing the source
|
2011-04-27 10:05:43 +00:00
|
|
|
code's file name and line number, saying that the program ran out
|
2015-02-25 10:05:29 +00:00
|
|
|
of memory and aborts program execution. It throws \c std::bad_alloc instead
|
|
|
|
if exceptions are enabled.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-02-25 10:05:29 +00:00
|
|
|
Q_CHECK_PTR does nothing if \c QT_NO_DEBUG and \c QT_NO_EXCEPTIONS were
|
|
|
|
defined during compilation. Therefore you must not use Q_CHECK_PTR to check
|
|
|
|
for successful memory allocations because the check will be disabled in
|
|
|
|
some cases.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 21
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qWarning(), {Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn T *q_check_ptr(T *pointer)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
2012-07-23 14:31:30 +00:00
|
|
|
Uses Q_CHECK_PTR on \a pointer, then returns \a pointer.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
This can be used as an inline version of Q_CHECK_PTR.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro const char* Q_FUNC_INFO()
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Expands to a string that describe the function the macro resides in. How this string looks
|
|
|
|
more specifically is compiler dependent. With GNU GCC it is typically the function signature,
|
|
|
|
while with other compilers it might be the line and column number.
|
|
|
|
|
|
|
|
Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 22
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
when instantiated with the integer type, will with the GCC compiler produce:
|
|
|
|
|
|
|
|
\tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
|
|
|
|
|
|
|
|
If this macro is used outside a function, the behavior is undefined.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
The Q_CHECK_PTR macro calls this function if an allocation check
|
|
|
|
fails.
|
|
|
|
*/
|
|
|
|
void qt_check_pointer(const char *n, int l)
|
|
|
|
{
|
|
|
|
qFatal("In file %s, line %d: Out of memory", n, l);
|
|
|
|
}
|
|
|
|
|
2012-08-15 05:37:01 +00:00
|
|
|
/*
|
|
|
|
\internal
|
2011-04-27 10:05:43 +00:00
|
|
|
Allows you to throw an exception without including <new>
|
|
|
|
Called internally from Q_CHECK_PTR on certain OS combinations
|
|
|
|
*/
|
|
|
|
void qBadAlloc()
|
|
|
|
{
|
|
|
|
QT_THROW(std::bad_alloc());
|
|
|
|
}
|
|
|
|
|
2012-09-12 12:27:18 +00:00
|
|
|
#ifndef QT_NO_EXCEPTIONS
|
2012-08-15 05:37:01 +00:00
|
|
|
/*
|
|
|
|
\internal
|
2012-08-03 08:38:00 +00:00
|
|
|
Allows you to call std::terminate() without including <exception>.
|
|
|
|
Called internally from QT_TERMINATE_ON_EXCEPTION
|
|
|
|
*/
|
|
|
|
Q_NORETURN void qTerminate() Q_DECL_NOTHROW
|
|
|
|
{
|
|
|
|
std::terminate();
|
|
|
|
}
|
2012-09-12 12:27:18 +00:00
|
|
|
#endif
|
2012-08-03 08:38:00 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*
|
|
|
|
The Q_ASSERT macro calls this function when the test fails.
|
|
|
|
*/
|
2012-08-03 08:38:00 +00:00
|
|
|
void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The Q_ASSERT_X macro calls this function when the test fails.
|
|
|
|
*/
|
2012-08-03 08:38:00 +00:00
|
|
|
void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Dijkstra's bisection algorithm to find the square root of an integer.
|
|
|
|
Deliberately not exported as part of the Qt API, but used in both
|
|
|
|
qsimplerichtext.cpp and qgfxraster_qws.cpp
|
|
|
|
*/
|
|
|
|
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
|
|
|
|
{
|
|
|
|
// n must be in the range 0...UINT_MAX/2-1
|
|
|
|
if (n >= (UINT_MAX>>2)) {
|
|
|
|
unsigned int r = 2 * qt_int_sqrt(n / 4);
|
|
|
|
unsigned int r2 = r + 1;
|
|
|
|
return (n >= r2 * r2) ? r2 : r;
|
|
|
|
}
|
|
|
|
uint h, p= 0, q= 1, r= n;
|
|
|
|
while (q <= n)
|
|
|
|
q <<= 2;
|
|
|
|
while (q != 1) {
|
|
|
|
q >>= 2;
|
|
|
|
h= p + q;
|
|
|
|
p >>= 1;
|
|
|
|
if (r >= h) {
|
|
|
|
p += q;
|
|
|
|
r -= h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
|
|
|
|
void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
|
|
|
|
|
|
|
|
#if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \
|
|
|
|
defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
|
|
|
|
namespace {
|
|
|
|
// There are two incompatible versions of strerror_r:
|
|
|
|
// a) the XSI/POSIX.1 version, which returns an int,
|
|
|
|
// indicating success or not
|
|
|
|
// b) the GNU version, which returns a char*, which may or may not
|
|
|
|
// be the beginning of the buffer we used
|
2012-09-24 16:12:43 +00:00
|
|
|
// The GNU libc manpage for strerror_r says you should use the XSI
|
2011-04-27 10:05:43 +00:00
|
|
|
// version in portable code. However, it's impossible to do that if
|
|
|
|
// _GNU_SOURCE is defined so we use C++ overloading to decide what to do
|
|
|
|
// depending on the return type
|
2013-06-28 20:15:13 +00:00
|
|
|
static inline Q_DECL_UNUSED QString fromstrerror_helper(int, const QByteArray &buf)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-05-29 10:29:55 +00:00
|
|
|
return QString::fromLocal8Bit(buf.constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2013-06-28 20:15:13 +00:00
|
|
|
static inline Q_DECL_UNUSED QString fromstrerror_helper(const char *str, const QByteArray &)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return QString::fromLocal8Bit(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString qt_error_string(int errorCode)
|
|
|
|
{
|
|
|
|
const char *s = 0;
|
|
|
|
QString ret;
|
|
|
|
if (errorCode == -1) {
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
errorCode = GetLastError();
|
|
|
|
#else
|
|
|
|
errorCode = errno;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
switch (errorCode) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case EACCES:
|
|
|
|
s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
|
|
|
|
break;
|
|
|
|
case EMFILE:
|
|
|
|
s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
|
|
|
|
break;
|
|
|
|
case ENOENT:
|
|
|
|
s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
|
|
|
|
break;
|
|
|
|
case ENOSPC:
|
|
|
|
s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
|
|
|
|
break;
|
|
|
|
default: {
|
2013-09-04 11:07:56 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
// Retrieve the system error message for the last-error code.
|
|
|
|
# ifndef Q_OS_WINRT
|
2011-04-27 10:05:43 +00:00
|
|
|
wchar_t *string = 0;
|
2015-04-01 14:04:14 +00:00
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
2011-04-27 10:05:43 +00:00
|
|
|
NULL,
|
|
|
|
errorCode,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPWSTR)&string,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
ret = QString::fromWCharArray(string);
|
|
|
|
LocalFree((HLOCAL)string);
|
2013-09-04 11:07:56 +00:00
|
|
|
# else // !Q_OS_WINRT
|
|
|
|
__declspec(thread) static wchar_t errorString[4096];
|
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
errorCode,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
errorString,
|
|
|
|
ARRAYSIZE(errorString),
|
|
|
|
NULL);
|
|
|
|
ret = QString::fromWCharArray(errorString);
|
|
|
|
# endif // Q_OS_WINRT
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
|
|
|
|
ret = QString::fromLatin1("The specified module could not be found.");
|
|
|
|
#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
|
|
|
|
QByteArray buf(1024, '\0');
|
|
|
|
ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
|
|
|
|
#else
|
|
|
|
ret = QString::fromLocal8Bit(strerror(errorCode));
|
|
|
|
#endif
|
|
|
|
break; }
|
|
|
|
}
|
|
|
|
if (s)
|
|
|
|
// ######## this breaks moc build currently
|
|
|
|
// ret = QCoreApplication::translate("QIODevice", s);
|
|
|
|
ret = QString::fromLatin1(s);
|
|
|
|
return ret.trimmed();
|
|
|
|
}
|
|
|
|
|
2015-04-24 08:47:29 +00:00
|
|
|
// In the C runtime on all platforms access to the environment is not thread-safe. We
|
|
|
|
// add thread-safety for the Qt wrappers.
|
|
|
|
static QBasicMutex environmentMutex;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// getenv is declared as deprecated in VS2005. This function
|
|
|
|
// makes use of the new secure getenv function.
|
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns the value of the environment variable with name \a
|
|
|
|
varName. To get the variable string, use QByteArray::constData().
|
2017-03-05 16:28:56 +00:00
|
|
|
To convert the data to a QString use QString::fromLocal8Bit().
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\note qgetenv() was introduced because getenv() from the standard
|
|
|
|
C library was deprecated in VC2005 (and later versions). qgetenv()
|
|
|
|
uses the new replacement function in VC, and calls the standard C
|
|
|
|
library's implementation on all other platforms.
|
|
|
|
|
2017-03-05 16:28:56 +00:00
|
|
|
\warning Don't use qgetenv on Windows if the content may contain
|
|
|
|
non-US-ASCII characters, like file paths.
|
|
|
|
|
2012-08-06 22:24:11 +00:00
|
|
|
\sa qputenv(), qEnvironmentVariableIsSet(), qEnvironmentVariableIsEmpty()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
QByteArray qgetenv(const char *varName)
|
|
|
|
{
|
2015-04-24 08:47:29 +00:00
|
|
|
QMutexLocker locker(&environmentMutex);
|
2011-04-27 10:05:43 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
size_t requiredSize = 0;
|
|
|
|
QByteArray buffer;
|
|
|
|
getenv_s(&requiredSize, 0, 0, varName);
|
|
|
|
if (requiredSize == 0)
|
|
|
|
return buffer;
|
|
|
|
buffer.resize(int(requiredSize));
|
|
|
|
getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
|
|
|
|
// requiredSize includes the terminating null, which we don't want.
|
|
|
|
Q_ASSERT(buffer.endsWith('\0'));
|
|
|
|
buffer.chop(1);
|
|
|
|
return buffer;
|
|
|
|
#else
|
|
|
|
return QByteArray(::getenv(varName));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-03 10:46:15 +00:00
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
2012-08-06 22:24:11 +00:00
|
|
|
\since 5.1
|
2012-08-03 10:46:15 +00:00
|
|
|
|
2012-08-06 22:24:11 +00:00
|
|
|
Returns whether the environment variable \a varName is empty.
|
2012-08-03 10:46:15 +00:00
|
|
|
|
|
|
|
Equivalent to
|
|
|
|
\code
|
|
|
|
qgetenv(varName).isEmpty()
|
|
|
|
\endcode
|
|
|
|
except that it's potentially much faster, and can't throw exceptions.
|
|
|
|
|
|
|
|
\sa qgetenv(), qEnvironmentVariableIsSet()
|
|
|
|
*/
|
|
|
|
bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT
|
|
|
|
{
|
2015-04-24 08:47:29 +00:00
|
|
|
QMutexLocker locker(&environmentMutex);
|
2012-08-03 10:46:15 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
// we provide a buffer that can only hold the empty string, so
|
|
|
|
// when the env.var isn't empty, we'll get an ERANGE error (buffer
|
|
|
|
// too small):
|
|
|
|
size_t dummy;
|
|
|
|
char buffer = '\0';
|
|
|
|
return getenv_s(&dummy, &buffer, 1, varName) != ERANGE;
|
|
|
|
#else
|
|
|
|
const char * const value = ::getenv(varName);
|
|
|
|
return !value || !*value;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-07 19:11:55 +00:00
|
|
|
/*!
|
|
|
|
\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
|
2016-08-03 23:04:22 +00:00
|
|
|
qgetenv(varName).toInt(ok, 0)
|
2014-09-07 19:11:55 +00:00
|
|
|
\endcode
|
|
|
|
except that it's much faster, and can't throw exceptions.
|
|
|
|
|
2016-08-03 23:04:22 +00:00
|
|
|
\note there's a limit on the length of the value, which is sufficient for
|
|
|
|
all valid values of int, not counting leading zeroes or spaces. Values that
|
|
|
|
are too long will either be truncated or this function will set \a ok to \c
|
|
|
|
false.
|
|
|
|
|
2014-09-07 19:11:55 +00:00
|
|
|
\sa qgetenv(), qEnvironmentVariableIsSet()
|
|
|
|
*/
|
|
|
|
int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT
|
|
|
|
{
|
|
|
|
static const int NumBinaryDigitsPerOctalDigit = 3;
|
|
|
|
static const int MaxDigitsForOctalInt =
|
|
|
|
(std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit;
|
2016-08-03 23:04:22 +00:00
|
|
|
|
|
|
|
QMutexLocker locker(&environmentMutex);
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
// we provide a buffer that can hold any int value:
|
2014-09-07 19:11:55 +00:00
|
|
|
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);
|
2016-08-03 23:04:22 +00:00
|
|
|
if (!buffer || strlen(buffer) > MaxDigitsForOctalInt + 2) {
|
2014-09-07 19:11:55 +00:00
|
|
|
if (ok)
|
|
|
|
*ok = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-04 22:14:23 +00:00
|
|
|
bool ok_ = true;
|
2016-08-03 23:04:22 +00:00
|
|
|
const char *endptr;
|
|
|
|
const qlonglong value = qstrtoll(buffer, &endptr, 0, &ok_);
|
|
|
|
if (int(value) != value || *endptr != '\0') { // this is the check in QByteArray::toInt(), keep it in sync
|
2014-09-07 19:11:55 +00:00
|
|
|
if (ok)
|
|
|
|
*ok = false;
|
|
|
|
return 0;
|
2014-02-04 22:14:23 +00:00
|
|
|
} else if (ok) {
|
|
|
|
*ok = ok_;
|
2014-09-07 19:11:55 +00:00
|
|
|
}
|
|
|
|
return int(value);
|
|
|
|
}
|
|
|
|
|
2012-08-03 10:46:15 +00:00
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
2012-08-06 22:24:11 +00:00
|
|
|
\since 5.1
|
2012-08-03 10:46:15 +00:00
|
|
|
|
2012-08-06 22:24:11 +00:00
|
|
|
Returns whether the environment variable \a varName is set.
|
2012-08-03 10:46:15 +00:00
|
|
|
|
|
|
|
Equivalent to
|
|
|
|
\code
|
|
|
|
!qgetenv(varName).isNull()
|
|
|
|
\endcode
|
|
|
|
except that it's potentially much faster, and can't throw exceptions.
|
|
|
|
|
|
|
|
\sa qgetenv(), qEnvironmentVariableIsEmpty()
|
|
|
|
*/
|
|
|
|
bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT
|
|
|
|
{
|
2015-04-24 08:47:29 +00:00
|
|
|
QMutexLocker locker(&environmentMutex);
|
2012-08-03 10:46:15 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
size_t requiredSize = 0;
|
|
|
|
(void)getenv_s(&requiredSize, 0, 0, varName);
|
|
|
|
return requiredSize != 0;
|
|
|
|
#else
|
|
|
|
return ::getenv(varName) != 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This function sets the \a value of the environment variable named
|
|
|
|
\a varName. It will create the variable if it does not exist. It
|
|
|
|
returns 0 if the variable could not be set.
|
|
|
|
|
2013-01-12 09:12:47 +00:00
|
|
|
Calling qputenv with an empty value removes the environment variable on
|
|
|
|
Windows, and makes it set (but empty) on Unix. Prefer using qunsetenv()
|
|
|
|
for fully portable behavior.
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
\note qputenv() was introduced because putenv() from the standard
|
|
|
|
C library was deprecated in VC2005 (and later versions). qputenv()
|
|
|
|
uses the replacement function in VC, and calls the standard C
|
|
|
|
library's implementation on all other platforms.
|
|
|
|
|
|
|
|
\sa qgetenv()
|
|
|
|
*/
|
|
|
|
bool qputenv(const char *varName, const QByteArray& value)
|
|
|
|
{
|
2015-04-24 08:47:29 +00:00
|
|
|
QMutexLocker locker(&environmentMutex);
|
2011-04-27 10:05:43 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
return _putenv_s(varName, value.constData()) == 0;
|
2015-01-23 07:53:41 +00:00
|
|
|
#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_HAIKU)
|
2012-09-07 14:13:36 +00:00
|
|
|
// POSIX.1-2001 has setenv
|
|
|
|
return setenv(varName, value.constData(), true) == 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
|
|
|
QByteArray buffer(varName);
|
|
|
|
buffer += '=';
|
|
|
|
buffer += value;
|
|
|
|
char* envVar = qstrdup(buffer.constData());
|
|
|
|
int result = putenv(envVar);
|
|
|
|
if (result != 0) // error. we have to delete the string.
|
|
|
|
delete[] envVar;
|
|
|
|
return result == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-12 09:12:47 +00:00
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This function deletes the variable \a varName from the environment.
|
|
|
|
|
2013-10-02 14:51:05 +00:00
|
|
|
Returns \c true on success.
|
2013-01-12 09:12:47 +00:00
|
|
|
|
|
|
|
\since 5.1
|
|
|
|
|
|
|
|
\sa qputenv(), qgetenv()
|
|
|
|
*/
|
|
|
|
bool qunsetenv(const char *varName)
|
|
|
|
{
|
2015-04-24 08:47:29 +00:00
|
|
|
QMutexLocker locker(&environmentMutex);
|
2013-01-12 09:12:47 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
return _putenv_s(varName, "") == 0;
|
2015-01-23 07:53:41 +00:00
|
|
|
#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4) || defined(Q_OS_HAIKU)
|
|
|
|
// POSIX.1-2001, BSD and Haiku have unsetenv
|
2013-01-12 09:12:47 +00:00
|
|
|
return unsetenv(varName) == 0;
|
|
|
|
#elif defined(Q_CC_MINGW)
|
|
|
|
// On mingw, putenv("var=") removes "var" from the environment
|
|
|
|
QByteArray buffer(varName);
|
|
|
|
buffer += '=';
|
|
|
|
return putenv(buffer.constData()) == 0;
|
|
|
|
#else
|
|
|
|
// Fallback to putenv("var=") which will insert an empty var into the
|
|
|
|
// environment and leak it
|
|
|
|
QByteArray buffer(varName);
|
|
|
|
buffer += '=';
|
|
|
|
char *envVar = qstrdup(buffer.constData());
|
|
|
|
return putenv(envVar) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-06 07:42:28 +00:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
# if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
|
|
|
|
// older versions of INTEGRITY used a long instead of a uint for the seed.
|
|
|
|
typedef long SeedStorageType;
|
|
|
|
# else
|
|
|
|
typedef uint SeedStorageType;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
typedef QThreadStorage<SeedStorageType *> SeedStorage;
|
|
|
|
Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value
|
|
|
|
|
2016-03-18 09:49:43 +00:00
|
|
|
#elif defined(Q_OS_ANDROID)
|
2013-10-11 12:55:33 +00:00
|
|
|
typedef QThreadStorage<QJNIObjectPrivate> AndroidRandomStorage;
|
|
|
|
Q_GLOBAL_STATIC(AndroidRandomStorage, randomTLS)
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.2
|
|
|
|
|
|
|
|
Thread-safe version of the standard C++ \c srand() function.
|
|
|
|
|
|
|
|
Sets the argument \a seed to be used to generate a new random number sequence of
|
|
|
|
pseudo random integers to be returned by qrand().
|
|
|
|
|
|
|
|
The sequence of random numbers generated is deterministic per thread. For example,
|
2016-09-29 15:05:07 +00:00
|
|
|
if two threads call qsrand(1) and subsequently call qrand(), the threads will get
|
2011-04-27 10:05:43 +00:00
|
|
|
the same random number sequence.
|
|
|
|
|
|
|
|
\sa qrand()
|
|
|
|
*/
|
|
|
|
void qsrand(uint seed)
|
|
|
|
{
|
2013-08-02 14:12:40 +00:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0)
|
2011-04-27 10:05:43 +00:00
|
|
|
SeedStorage *seedStorage = randTLS();
|
|
|
|
if (seedStorage) {
|
|
|
|
SeedStorageType *pseed = seedStorage->localData();
|
|
|
|
if (!pseed)
|
|
|
|
seedStorage->setLocalData(pseed = new SeedStorageType);
|
|
|
|
*pseed = seed;
|
|
|
|
} else {
|
|
|
|
//global static seed storage should always exist,
|
|
|
|
//except after being deleted by QGlobalStaticDeleter.
|
|
|
|
//But since it still can be called from destructor of another
|
|
|
|
//global static object, fallback to srand(seed)
|
|
|
|
srand(seed);
|
|
|
|
}
|
2016-03-18 09:49:43 +00:00
|
|
|
#elif defined(Q_OS_ANDROID)
|
2013-10-24 14:47:32 +00:00
|
|
|
if (randomTLS->hasLocalData()) {
|
|
|
|
randomTLS->localData().callMethod<void>("setSeed", "(J)V", jlong(seed));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJNIObjectPrivate random("java/util/Random",
|
|
|
|
"(J)V",
|
|
|
|
jlong(seed));
|
2013-10-11 12:55:33 +00:00
|
|
|
if (!random.isValid()) {
|
|
|
|
srand(seed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
randomTLS->setLocalData(random);
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2012-01-15 12:51:04 +00:00
|
|
|
// On Windows srand() and rand() already use Thread-Local-Storage
|
2011-04-27 10:05:43 +00:00
|
|
|
// to store the seed between calls
|
|
|
|
// this is also valid for QT_NO_THREAD
|
|
|
|
srand(seed);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.2
|
|
|
|
|
|
|
|
Thread-safe version of the standard C++ \c rand() function.
|
|
|
|
|
|
|
|
Returns a value between 0 and \c RAND_MAX (defined in \c <cstdlib> and
|
|
|
|
\c <stdlib.h>), the next number in the current sequence of pseudo-random
|
|
|
|
integers.
|
|
|
|
|
|
|
|
Use \c qsrand() to initialize the pseudo-random number generator with
|
|
|
|
a seed value.
|
|
|
|
|
|
|
|
\sa qsrand()
|
|
|
|
*/
|
|
|
|
int qrand()
|
|
|
|
{
|
2012-07-01 06:19:59 +00:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0)
|
2011-04-27 10:05:43 +00:00
|
|
|
SeedStorage *seedStorage = randTLS();
|
|
|
|
if (seedStorage) {
|
|
|
|
SeedStorageType *pseed = seedStorage->localData();
|
|
|
|
if (!pseed) {
|
|
|
|
seedStorage->setLocalData(pseed = new SeedStorageType);
|
|
|
|
*pseed = 1;
|
|
|
|
}
|
|
|
|
return rand_r(pseed);
|
|
|
|
} else {
|
|
|
|
//global static seed storage should always exist,
|
|
|
|
//except after being deleted by QGlobalStaticDeleter.
|
|
|
|
//But since it still can be called from destructor of another
|
|
|
|
//global static object, fallback to rand()
|
|
|
|
return rand();
|
|
|
|
}
|
2016-03-18 09:49:43 +00:00
|
|
|
#elif defined(Q_OS_ANDROID)
|
2013-10-11 12:55:33 +00:00
|
|
|
AndroidRandomStorage *randomStorage = randomTLS();
|
|
|
|
if (!randomStorage)
|
|
|
|
return rand();
|
|
|
|
|
2013-10-24 14:47:32 +00:00
|
|
|
if (randomStorage->hasLocalData()) {
|
|
|
|
return randomStorage->localData().callMethod<jint>("nextInt",
|
|
|
|
"(I)I",
|
|
|
|
RAND_MAX);
|
2013-10-11 12:55:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 14:47:32 +00:00
|
|
|
QJNIObjectPrivate random("java/util/Random",
|
|
|
|
"(J)V",
|
|
|
|
jlong(1));
|
|
|
|
|
|
|
|
if (!random.isValid())
|
|
|
|
return rand();
|
|
|
|
|
|
|
|
randomStorage->setLocalData(random);
|
2013-10-11 12:55:33 +00:00
|
|
|
return random.callMethod<jint>("nextInt", "(I)I", RAND_MAX);
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2012-01-15 12:51:04 +00:00
|
|
|
// On Windows srand() and rand() already use Thread-Local-Storage
|
2011-04-27 10:05:43 +00:00
|
|
|
// to store the seed between calls
|
|
|
|
// this is also valid for QT_NO_THREAD
|
|
|
|
return rand();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro forever
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro is provided for convenience for writing infinite
|
|
|
|
loops.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 31
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
It is equivalent to \c{for (;;)}.
|
|
|
|
|
|
|
|
If you're worried about namespace pollution, you can disable this
|
|
|
|
macro by adding the following line to your \c .pro file:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 32
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_FOREVER
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_FOREVER
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Same as \l{forever}.
|
|
|
|
|
|
|
|
This macro is available even when \c no_keywords is specified
|
|
|
|
using the \c .pro file's \c CONFIG variable.
|
|
|
|
|
|
|
|
\sa foreach()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro foreach(variable, container)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro is used to implement Qt's \c foreach loop. The \a
|
|
|
|
variable parameter is a variable name or variable definition; the
|
|
|
|
\a container parameter is a Qt container whose value type
|
|
|
|
corresponds to the type of the variable. See \l{The foreach
|
|
|
|
Keyword} for details.
|
|
|
|
|
|
|
|
If you're worried about namespace pollution, you can disable this
|
|
|
|
macro by adding the following line to your \c .pro file:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 33
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-01-24 02:11:48 +00:00
|
|
|
\note Since Qt 5.7, the use of this macro is discouraged. It will
|
|
|
|
be removed in a future version of Qt. Please use C++11 range-for,
|
|
|
|
possibly with qAsConst(), as needed.
|
|
|
|
|
|
|
|
\sa qAsConst()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_FOREACH(variable, container)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Same as foreach(\a variable, \a container).
|
|
|
|
|
|
|
|
This macro is available even when \c no_keywords is specified
|
|
|
|
using the \c .pro file's \c CONFIG variable.
|
|
|
|
|
2016-01-24 02:11:48 +00:00
|
|
|
\note Since Qt 5.7, the use of this macro is discouraged. It will
|
|
|
|
be removed in a future version of Qt. Please use C++11 range-for,
|
|
|
|
possibly with qAsConst(), as needed.
|
|
|
|
|
|
|
|
\sa qAsConst()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-20 19:45:25 +00:00
|
|
|
/*!
|
|
|
|
\fn qAsConst(T &t)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
|
|
|
|
Returns \a t cast to \c{const T}.
|
|
|
|
|
|
|
|
This function is a Qt implementation of C++17's std::as_const(),
|
|
|
|
a cast function like std::move(). But while std::move() turns
|
|
|
|
lvalues into rvalues, this function turns non-const lvalues into
|
|
|
|
const lvalues. Like std::as_const(), it doesn't work on rvalues,
|
|
|
|
because it cannot be efficiently implemented for rvalues without
|
|
|
|
leaving dangling references.
|
|
|
|
|
|
|
|
Its main use in Qt is to prevent implicitly-shared Qt containers
|
|
|
|
from detaching:
|
|
|
|
\code
|
|
|
|
QString s = ...;
|
|
|
|
for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
|
|
|
|
process(ch);
|
|
|
|
for (QChar ch : qAsConst(s)) // ok, no detach attempt
|
|
|
|
process(ch);
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
Of course, in this case, you could (and probably should) have declared
|
|
|
|
\c s as \c const in the first place:
|
|
|
|
\code
|
|
|
|
const QString s = ...;
|
|
|
|
for (QChar ch : s) // ok, no detach attempt on const objects
|
|
|
|
process(ch);
|
|
|
|
\endcode
|
|
|
|
but often that is not easily possible.
|
|
|
|
|
|
|
|
It is important to note that qAsConst() does not copy its argument,
|
|
|
|
it just performs a \c{const_cast<const T&>(t)}. This is also the reason
|
|
|
|
why it is designed to fail for rvalues: The returned reference would go
|
|
|
|
stale too soon. So while this works (but detaches the returned object):
|
|
|
|
\code
|
|
|
|
for (QChar ch : funcReturningQString())
|
|
|
|
process(ch); // OK, the returned object is kept alive for the loop's duration
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
this would not:
|
|
|
|
\code
|
|
|
|
for (QChar ch : qAsConst(funcReturningQString()))
|
|
|
|
process(ch); // ERROR: ch is copied from deleted memory
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
To prevent this construct from compiling (and failing at runtime), qAsConst() has
|
|
|
|
a second, deleted, overload which binds to rvalues.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn qAsConst(const T &&t)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
\overload
|
|
|
|
|
|
|
|
This overload is deleted to prevent a dangling reference in code like
|
|
|
|
\code
|
|
|
|
for (QChar ch : qAsConst(funcReturningQString()))
|
|
|
|
process(ch); // ERROR: ch is copied from deleted memory
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro QT_TR_NOOP(sourceText)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Marks the string literal \a sourceText for dynamic translation in
|
|
|
|
the current context (class), i.e the stored \a sourceText will not
|
|
|
|
be altered.
|
|
|
|
|
|
|
|
The macro expands to \a sourceText.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 34
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
|
|
|
|
that the source string is encoded in UTF-8. Corresponding variants
|
2012-01-31 22:33:30 +00:00
|
|
|
exist in the QT_TRANSLATE_NOOP() family of macros, too.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_TRANSLATE_NOOP(context, sourceText)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Marks the string literal \a sourceText for dynamic translation in
|
|
|
|
the given \a context; i.e, the stored \a sourceText will not be
|
|
|
|
altered. The \a context is typically a class and also needs to
|
|
|
|
be specified as string literal.
|
|
|
|
|
|
|
|
The macro expands to \a sourceText.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 35
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_TRANSLATE_NOOP3(context, sourceText, comment)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.4
|
|
|
|
|
|
|
|
Marks the string literal \a sourceText for dynamic translation in the
|
|
|
|
given \a context and with \a comment, i.e the stored \a sourceText will
|
|
|
|
not be altered. The \a context is typically a class and also needs to
|
|
|
|
be specified as string literal. The string literal \a comment
|
|
|
|
will be available for translators using e.g. Qt Linguist.
|
|
|
|
|
|
|
|
The macro expands to anonymous struct of the two string
|
|
|
|
literals passed as \a sourceText and \a comment.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 36
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn QString qtTrId(const char *id, int n = -1)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\reentrant
|
|
|
|
\since 4.6
|
|
|
|
|
|
|
|
\brief The qtTrId function finds and returns a translated string.
|
|
|
|
|
|
|
|
Returns a translated string identified by \a id.
|
|
|
|
If no matching string is found, the id itself is returned. This
|
|
|
|
should not happen under normal conditions.
|
|
|
|
|
|
|
|
If \a n >= 0, all occurrences of \c %n in the resulting string
|
|
|
|
are replaced with a decimal representation of \a n. In addition,
|
|
|
|
depending on \a n's value, the translation text may vary.
|
|
|
|
|
|
|
|
Meta data and comments can be passed as documented for QObject::tr().
|
|
|
|
In addition, it is possible to supply a source string template like that:
|
|
|
|
|
|
|
|
\tt{//% <C string>}
|
|
|
|
|
|
|
|
or
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\tt{\\begincomment% <C string> \\endcomment}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qttrid
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Creating QM files suitable for use with this function requires passing
|
|
|
|
the \c -idbased option to the \c lrelease tool.
|
|
|
|
|
|
|
|
\warning This method is reentrant only if all translators are
|
|
|
|
installed \e before calling this method. Installing or removing
|
|
|
|
translators while performing translations is not supported. Doing
|
|
|
|
so will probably result in crashes or other undesirable behavior.
|
|
|
|
|
|
|
|
\sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_TRID_NOOP(id)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.6
|
|
|
|
|
|
|
|
\brief The QT_TRID_NOOP macro marks an id for dynamic translation.
|
|
|
|
|
|
|
|
The only purpose of this macro is to provide an anchor for attaching
|
|
|
|
meta data like to qtTrId().
|
|
|
|
|
|
|
|
The macro expands to \a id.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qttrid_noop
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa qtTrId(), {Internationalization with Qt}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_LIKELY(expr)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.8
|
|
|
|
|
2011-05-10 17:52:50 +00:00
|
|
|
\brief Hints to the compiler that the enclosed condition, \a expr, is
|
|
|
|
likely to evaluate to \c true.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Use of this macro can help the compiler to optimize the code.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qlikely
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_UNLIKELY()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_UNLIKELY(expr)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.8
|
|
|
|
|
2011-05-10 17:52:50 +00:00
|
|
|
\brief Hints to the compiler that the enclosed condition, \a expr, is
|
|
|
|
likely to evaluate to \c false.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Use of this macro can help the compiler to optimize the code.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qunlikely
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_LIKELY()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_POINTER_SIZE
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Expands to the size of a pointer in bytes (4 or 8). This is
|
|
|
|
equivalent to \c sizeof(void *) but can be used in a preprocessor
|
|
|
|
directive.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QABS(n)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\obsolete
|
|
|
|
|
|
|
|
Use qAbs(\a n) instead.
|
|
|
|
|
|
|
|
\sa QMIN(), QMAX()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QMIN(x, y)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\obsolete
|
|
|
|
|
|
|
|
Use qMin(\a x, \a y) instead.
|
|
|
|
|
|
|
|
\sa QMAX(), QABS()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QMAX(x, y)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\obsolete
|
|
|
|
|
|
|
|
Use qMax(\a x, \a y) instead.
|
|
|
|
|
|
|
|
\sa QMIN(), QABS()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro const char *qPrintable(const QString &str)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Returns \a str as a \c{const char *}. This is equivalent to
|
|
|
|
\a{str}.toLocal8Bit().constData().
|
|
|
|
|
|
|
|
The char pointer will be invalid after the statement in which
|
|
|
|
qPrintable() is used. This is because the array returned by
|
2014-02-24 08:29:41 +00:00
|
|
|
QString::toLocal8Bit() will fall out of scope.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\note qDebug(), qInfo(), qWarning(), qCritical(), qFatal() expect
|
|
|
|
%s arguments to be UTF-8 encoded, while qPrintable() converts to
|
2014-03-06 07:56:52 +00:00
|
|
|
local 8-bit encoding. Therefore qUtf8Printable() should be used
|
|
|
|
for logging strings instead of qPrintable().
|
|
|
|
|
|
|
|
\sa qUtf8Printable()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro const char *qUtf8Printable(const QString &str)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.4
|
|
|
|
|
|
|
|
Returns \a str as a \c{const char *}. This is equivalent to
|
|
|
|
\a{str}.toUtf8().constData().
|
|
|
|
|
|
|
|
The char pointer will be invalid after the statement in which
|
|
|
|
qUtf8Printable() is used. This is because the array returned by
|
|
|
|
QString::toUtf8() will fall out of scope.
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 37
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2015-11-12 08:59:37 +00:00
|
|
|
/*!
|
|
|
|
\macro const wchar_t *qUtf16Printable(const QString &str)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.7
|
|
|
|
|
|
|
|
Returns \a str as a \c{const ushort *}, but cast to a \c{const wchar_t *}
|
|
|
|
to avoid warnings. This is equivalent to \a{str}.utf16() plus some casting.
|
|
|
|
|
|
|
|
The only useful thing you can do with the return value of this macro is to
|
|
|
|
pass it to QString::asprintf() for use in a \c{%ls} conversion. In particular,
|
|
|
|
the return value is \e{not} a valid \c{const wchar_t*}!
|
|
|
|
|
|
|
|
In general, the pointer will be invalid after the statement in which
|
|
|
|
qUtf16Printable() is used. This is because the pointer may have been
|
|
|
|
obtained from a temporary expression, which will fall out of scope.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qUtf16Printable
|
|
|
|
|
|
|
|
\sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DECLARE_TYPEINFO(Type, Flags)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
You can use this macro to specify information about a custom type
|
|
|
|
\a Type. With accurate type information, Qt's \l{Container Classes}
|
|
|
|
{generic containers} can choose appropriate storage methods and
|
|
|
|
algorithms.
|
|
|
|
|
|
|
|
\a Flags can be one of the following:
|
|
|
|
|
|
|
|
\list
|
2012-03-01 14:28:31 +00:00
|
|
|
\li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
|
2012-03-30 12:09:15 +00:00
|
|
|
data) type with no constructor or destructor, or else a type where
|
|
|
|
every bit pattern is a valid object and memcpy() creates a valid
|
|
|
|
independent copy of the object.
|
2012-03-01 14:28:31 +00:00
|
|
|
\li \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
|
2011-04-27 10:05:43 +00:00
|
|
|
and/or a destructor but can be moved in memory using \c
|
2015-11-10 16:34:00 +00:00
|
|
|
memcpy(). Note: despite the name, this has nothing to do with move
|
|
|
|
constructors or C++ move semantics.
|
2012-03-01 14:28:31 +00:00
|
|
|
\li \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
|
2011-04-27 10:05:43 +00:00
|
|
|
constructors and/or a destructor and that it may not be moved
|
|
|
|
in memory.
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
Example of a "primitive" type:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 38
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-30 12:09:15 +00:00
|
|
|
An example of a non-POD "primitive" type is QUuid: Even though
|
|
|
|
QUuid has constructors (and therefore isn't POD), every bit
|
|
|
|
pattern still represents a valid object, and memcpy() can be used
|
|
|
|
to create a valid independent copy of a QUuid object.
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
Example of a movable type:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 39
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_UNUSED(name)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Indicates to the compiler that the parameter with the specified
|
|
|
|
\a name is not used in the body of a function. This can be used to
|
|
|
|
suppress compiler warnings while allowing functions to be defined
|
|
|
|
with meaningful parameter names in their signatures.
|
|
|
|
*/
|
|
|
|
|
2011-12-05 12:46:39 +00:00
|
|
|
struct QInternal_CallBackTable {
|
|
|
|
QVector<QList<qInternalCallback> > callbacks;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
|
|
|
|
|
|
|
|
bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
|
|
|
|
{
|
|
|
|
if (cb >= 0 && cb < QInternal::LastCallback) {
|
|
|
|
QInternal_CallBackTable *cbt = global_callback_table();
|
|
|
|
cbt->callbacks.resize(cb + 1);
|
|
|
|
cbt->callbacks[cb].append(callback);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
|
|
|
|
{
|
|
|
|
if (cb >= 0 && cb < QInternal::LastCallback) {
|
2017-05-03 21:08:50 +00:00
|
|
|
if (global_callback_table.exists()) {
|
|
|
|
QInternal_CallBackTable *cbt = global_callback_table();
|
|
|
|
return (bool) cbt->callbacks[cb].removeAll(callback);
|
|
|
|
}
|
2011-12-05 12:46:39 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QInternal::activateCallbacks(Callback cb, void **parameters)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
|
|
|
|
|
2017-02-07 03:41:46 +00:00
|
|
|
if (!global_callback_table.exists())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QInternal_CallBackTable *cbt = &(*global_callback_table);
|
2011-12-05 12:46:39 +00:00
|
|
|
if (cbt && cb < cbt->callbacks.size()) {
|
|
|
|
QList<qInternalCallback> callbacks = cbt->callbacks[cb];
|
|
|
|
bool ret = false;
|
|
|
|
for (int i=0; i<callbacks.size(); ++i)
|
|
|
|
ret |= (callbacks.at(i))(parameters);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_BYTE_ORDER
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be used to determine the byte order your system
|
|
|
|
uses for storing data in memory. i.e., whether your system is
|
|
|
|
little-endian or big-endian. It is set by Qt to one of the macros
|
|
|
|
Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
|
|
|
|
about endian-ness, but you might, for example if you need to know
|
|
|
|
which byte of an integer or UTF-16 character is stored in the
|
|
|
|
lowest address. Endian-ness is important in networking, where
|
|
|
|
computers with different values for Q_BYTE_ORDER must pass data
|
|
|
|
back and forth.
|
|
|
|
|
|
|
|
Use this macro as in the following examples.
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 40
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_LITTLE_ENDIAN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro represents a value you can compare to the macro
|
|
|
|
Q_BYTE_ORDER to determine the endian-ness of your system. In a
|
|
|
|
little-endian system, the least significant byte is stored at the
|
|
|
|
lowest address. The other bytes follow in increasing order of
|
|
|
|
significance.
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 41
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_BYTE_ORDER, Q_BIG_ENDIAN
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_BIG_ENDIAN
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro represents a value you can compare to the macro
|
|
|
|
Q_BYTE_ORDER to determine the endian-ness of your system. In a
|
|
|
|
big-endian system, the most significant byte is stored at the
|
|
|
|
lowest address. The other bytes follow in decreasing order of
|
|
|
|
significance.
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 42
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_GLOBAL_STATIC(type, name)
|
|
|
|
\internal
|
|
|
|
|
|
|
|
Declares a global static variable with the given \a type and \a name.
|
|
|
|
|
|
|
|
Use this macro to instantiate an object in a thread-safe way, creating
|
|
|
|
a global pointer that can be used to refer to it.
|
|
|
|
|
|
|
|
\warning This macro is subject to a race condition that can cause the object
|
|
|
|
to be constructed twice. However, if this occurs, the second instance will
|
|
|
|
be immediately deleted.
|
|
|
|
|
|
|
|
See also
|
|
|
|
\l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
|
|
|
|
by Scott Meyers and Andrei Alexandrescu.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_GLOBAL_STATIC_WITH_ARGS(type, name, arguments)
|
|
|
|
\internal
|
|
|
|
|
|
|
|
Declares a global static variable with the specified \a type and \a name.
|
|
|
|
|
|
|
|
Use this macro to instantiate an object using the \a arguments specified
|
|
|
|
in a thread-safe way, creating a global pointer that can be used to refer
|
|
|
|
to it.
|
|
|
|
|
|
|
|
\warning This macro is subject to a race condition that can cause the object
|
|
|
|
to be constructed twice. However, if this occurs, the second instance will
|
|
|
|
be immediately deleted.
|
|
|
|
|
|
|
|
See also
|
|
|
|
\l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
|
|
|
|
by Scott Meyers and Andrei Alexandrescu.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
If this macro is defined to \c ns all Qt classes are put in a namespace
|
|
|
|
called \c ns. Also, moc will output code putting metaobjects etc.
|
|
|
|
into namespace \c ns.
|
|
|
|
|
|
|
|
\sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
|
|
|
|
QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
|
|
|
|
QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
|
|
|
|
QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_PREPEND_NAMESPACE(identifier)
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro qualifies \a identifier with the full namespace.
|
|
|
|
It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
|
|
|
|
and only \a identifier otherwise.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_USE_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
|
|
|
|
and nothing otherwise.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_BEGIN_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro expands to
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp begin namespace macro
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if \c QT_NAMESPACE is defined and nothing otherwise. If should always
|
|
|
|
appear in the file-level scope and be followed by \c QT_END_NAMESPACE
|
|
|
|
at the same logical level with respect to preprocessor conditionals
|
|
|
|
in the same file.
|
|
|
|
|
|
|
|
As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
|
|
|
|
and Qt source files after the last \c{#include} line and before the first
|
2013-01-30 19:06:45 +00:00
|
|
|
declaration.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If that rule can't be followed because, e.g., \c{#include} lines and
|
|
|
|
declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
|
|
|
|
the first declaration and wrap the \c{#include} lines in
|
|
|
|
\c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
|
|
|
|
|
|
|
|
When using the \c QT_NAMESPACE feature in user code
|
|
|
|
(e.g., when building plugins statically linked to Qt) where
|
|
|
|
the user code is not intended to go into the \c QT_NAMESPACE
|
|
|
|
namespace, all forward declarations of Qt classes need to
|
|
|
|
be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
|
|
|
|
After that, a \c QT_USE_NAMESPACE should follow.
|
|
|
|
No further changes should be needed.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_END_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro expands to
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp end namespace macro
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
|
|
|
|
the effect of \c QT_BEGIN_NAMESPACE.
|
|
|
|
|
|
|
|
If a source file ends with a \c{#include} directive that includes a moc file,
|
|
|
|
\c QT_END_NAMESPACE should be placed before that \c{#include}.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_BEGIN_INCLUDE_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro is equivalent to \c QT_END_NAMESPACE.
|
|
|
|
It only serves as syntactic sugar and is intended
|
|
|
|
to be used before #include lines within a
|
|
|
|
\c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_END_INCLUDE_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro is equivalent to \c QT_BEGIN_NAMESPACE.
|
|
|
|
It only serves as syntactic sugar and is intended
|
|
|
|
to be used after #include lines within a
|
|
|
|
\c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_BEGIN_MOC_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro is output by moc at the beginning of
|
|
|
|
moc files. It is equivalent to \c QT_USE_NAMESPACE.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro QT_END_MOC_NAMESPACE
|
|
|
|
\internal
|
|
|
|
|
|
|
|
This macro is output by moc at the beginning of
|
|
|
|
moc files. It expands to nothing.
|
|
|
|
|
|
|
|
\sa QT_NAMESPACE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool qFuzzyCompare(double p1, double p2)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.4
|
|
|
|
\threadsafe
|
|
|
|
|
|
|
|
Compares the floating point value \a p1 and \a p2 and
|
|
|
|
returns \c true if they are considered equal, otherwise \c false.
|
|
|
|
|
2016-09-28 08:13:27 +00:00
|
|
|
Note that comparing values where either \a p1 or \a p2 is 0.0 will not work,
|
|
|
|
nor does comparing values where one of the values is NaN or infinity.
|
|
|
|
If one of the values is always 0.0, use qFuzzyIsNull instead. If one of the
|
|
|
|
values is likely to be 0.0, one solution is to add 1.0 to both values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 46
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
The two numbers are compared in a relative way, where the
|
|
|
|
exactness is stronger the smaller the numbers are.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool qFuzzyCompare(float p1, float p2)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.4
|
|
|
|
\threadsafe
|
|
|
|
|
|
|
|
Compares the floating point value \a p1 and \a p2 and
|
|
|
|
returns \c true if they are considered equal, otherwise \c false.
|
|
|
|
|
|
|
|
The two numbers are compared in a relative way, where the
|
|
|
|
exactness is stronger the smaller the numbers are.
|
|
|
|
*/
|
|
|
|
|
2016-02-01 12:47:13 +00:00
|
|
|
/*!
|
|
|
|
\fn bool qFuzzyIsNull(double d)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.4
|
|
|
|
\threadsafe
|
|
|
|
|
|
|
|
Returns true if the absolute value of \a d is within 0.000000000001 of 0.0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool qFuzzyIsNull(float f)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 4.4
|
|
|
|
\threadsafe
|
|
|
|
|
|
|
|
Returns true if the absolute value of \a f is within 0.00001f of 0.0.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be used to ensure that the application is run
|
|
|
|
against a recent enough version of Qt. This is especially useful
|
|
|
|
if your application depends on a specific bug fix introduced in a
|
|
|
|
bug-fix release (e.g., 4.0.2).
|
|
|
|
|
|
|
|
The \a argc and \a argv parameters are the \c main() function's
|
|
|
|
\c argc and \c argv parameters. The \a version parameter is a
|
|
|
|
string literal that specifies which version of Qt the application
|
|
|
|
requires (e.g., "4.0.2").
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_gui_dialogs_qmessagebox.cpp 4
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECL_EXPORT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro marks a symbol for shared library export (see
|
|
|
|
\l{sharedlibrary.html}{Creating Shared Libraries}).
|
|
|
|
|
|
|
|
\sa Q_DECL_IMPORT
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECL_IMPORT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro declares a symbol to be an import from a shared library (see
|
|
|
|
\l{sharedlibrary.html}{Creating Shared Libraries}).
|
|
|
|
|
|
|
|
\sa Q_DECL_EXPORT
|
|
|
|
*/
|
|
|
|
|
2012-01-13 17:28:07 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DECL_CONSTEXPR
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be used to declare variable that should be constructed at compile-time,
|
|
|
|
or an inline function that can be computed at compile-time.
|
|
|
|
|
|
|
|
It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
|
|
|
|
otherwise.
|
2014-08-23 16:26:01 +00:00
|
|
|
|
|
|
|
\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
|
2012-01-13 17:28:07 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-02 10:17:28 +00:00
|
|
|
/*!
|
|
|
|
\macro qDebug(const char *message, ...)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Calls the message handler with the debug message \a message. If no
|
|
|
|
message handler has been installed, the message is printed to
|
2014-12-04 15:57:32 +00:00
|
|
|
stderr. Under Windows the message is sent to the console, if it is a
|
2015-10-15 13:24:54 +00:00
|
|
|
console application; otherwise, it is sent to the debugger. On QNX, the
|
2012-09-18 18:15:18 +00:00
|
|
|
message is sent to slogger2. This function does nothing if \c QT_NO_DEBUG_OUTPUT
|
|
|
|
was defined during compilation.
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
If you pass the function a format string and a list of arguments,
|
|
|
|
it works in similar way to the C printf() function. The format
|
|
|
|
should be a Latin-1 string.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 24
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
If you include \c <QtDebug>, a more convenient syntax is also
|
|
|
|
available:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 25
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
With this syntax, the function returns a QDebug object that is
|
|
|
|
configured to use the QtDebugMsg message type. It automatically
|
|
|
|
puts a single space between each item, and outputs a newline at
|
|
|
|
the end. It supports many C++ and Qt types.
|
|
|
|
|
|
|
|
To suppress the output at run-time, install your own message handler
|
|
|
|
with qInstallMessageHandler().
|
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\sa qInfo(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
|
|
|
|
{Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro qInfo(const char *message, ...)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.5
|
|
|
|
|
|
|
|
Calls the message handler with the informational message \a message. If no
|
|
|
|
message handler has been installed, the message is printed to
|
|
|
|
stderr. Under Windows, the message is sent to the console, if it is a
|
2015-10-15 13:24:54 +00:00
|
|
|
console application; otherwise, it is sent to the debugger. On QNX the
|
2014-12-04 15:57:32 +00:00
|
|
|
message is sent to slogger2. This function does nothing if \c QT_NO_INFO_OUTPUT
|
|
|
|
was defined during compilation.
|
|
|
|
|
|
|
|
If you pass the function a format string and a list of arguments,
|
|
|
|
it works in similar way to the C printf() function. The format
|
|
|
|
should be a Latin-1 string.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qInfo_printf
|
|
|
|
|
|
|
|
If you include \c <QtDebug>, a more convenient syntax is also
|
|
|
|
available:
|
|
|
|
|
|
|
|
\snippet code/src_corelib_global_qglobal.cpp qInfo_stream
|
|
|
|
|
|
|
|
With this syntax, the function returns a QDebug object that is
|
|
|
|
configured to use the QtInfoMsg message type. It automatically
|
|
|
|
puts a single space between each item, and outputs a newline at
|
|
|
|
the end. It supports many C++ and Qt types.
|
|
|
|
|
|
|
|
To suppress the output at run-time, install your own message handler
|
|
|
|
with qInstallMessageHandler().
|
|
|
|
|
|
|
|
\sa qDebug(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
|
2012-04-02 10:17:28 +00:00
|
|
|
{Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro qWarning(const char *message, ...)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Calls the message handler with the warning message \a message. If no
|
|
|
|
message handler has been installed, the message is printed to
|
2012-09-18 18:15:18 +00:00
|
|
|
stderr. Under Windows, the message is sent to the debugger.
|
2015-10-15 13:24:54 +00:00
|
|
|
On QNX the message is sent to slogger2. This
|
2012-04-02 10:17:28 +00:00
|
|
|
function does nothing if \c QT_NO_WARNING_OUTPUT was defined
|
|
|
|
during compilation; it exits if the environment variable \c
|
2014-03-07 11:17:22 +00:00
|
|
|
QT_FATAL_WARNINGS is not empty.
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
This function takes a format string and a list of arguments,
|
|
|
|
similar to the C printf() function. The format should be a Latin-1
|
|
|
|
string.
|
|
|
|
|
|
|
|
Example:
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 26
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
If you include <QtDebug>, a more convenient syntax is
|
|
|
|
also available:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 27
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
This syntax inserts a space between each item, and
|
|
|
|
appends a newline at the end.
|
|
|
|
|
|
|
|
To suppress the output at runtime, install your own message handler
|
|
|
|
with qInstallMessageHandler().
|
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\sa qDebug(), qInfo(), qCritical(), qFatal(), qInstallMessageHandler(),
|
2012-04-02 10:17:28 +00:00
|
|
|
{Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro qCritical(const char *message, ...)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Calls the message handler with the critical message \a message. If no
|
|
|
|
message handler has been installed, the message is printed to
|
|
|
|
stderr. Under Windows, the message is sent to the debugger.
|
2015-10-15 13:24:54 +00:00
|
|
|
On QNX the message is sent to slogger2
|
2012-04-02 10:17:28 +00:00
|
|
|
|
2014-03-07 11:20:30 +00:00
|
|
|
It exits if the environment variable QT_FATAL_CRITICALS is not empty.
|
|
|
|
|
2012-04-02 10:17:28 +00:00
|
|
|
This function takes a format string and a list of arguments,
|
|
|
|
similar to the C printf() function. The format should be a Latin-1
|
|
|
|
string.
|
|
|
|
|
|
|
|
Example:
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 28
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
If you include <QtDebug>, a more convenient syntax is
|
|
|
|
also available:
|
|
|
|
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 29
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
A space is inserted between the items, and a newline is
|
|
|
|
appended at the end.
|
|
|
|
|
|
|
|
To suppress the output at runtime, install your own message handler
|
|
|
|
with qInstallMessageHandler().
|
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\sa qDebug(), qInfo(), qWarning(), qFatal(), qInstallMessageHandler(),
|
2012-04-02 10:17:28 +00:00
|
|
|
{Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro qFatal(const char *message, ...)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Calls the message handler with the fatal message \a message. If no
|
|
|
|
message handler has been installed, the message is printed to
|
|
|
|
stderr. Under Windows, the message is sent to the debugger.
|
2015-10-15 13:24:54 +00:00
|
|
|
On QNX the message is sent to slogger2
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
If you are using the \b{default message handler} this function will
|
2016-07-16 12:49:19 +00:00
|
|
|
abort to create a core dump. On Windows, for debug builds,
|
2012-04-02 10:17:28 +00:00
|
|
|
this function will report a _CRT_ERROR enabling you to connect a debugger
|
|
|
|
to the application.
|
|
|
|
|
|
|
|
This function takes a format string and a list of arguments,
|
|
|
|
similar to the C printf() function.
|
|
|
|
|
|
|
|
Example:
|
2012-03-20 18:37:07 +00:00
|
|
|
\snippet code/src_corelib_global_qglobal.cpp 30
|
2012-04-02 10:17:28 +00:00
|
|
|
|
|
|
|
To suppress the output at runtime, install your own message handler
|
|
|
|
with qInstallMessageHandler().
|
|
|
|
|
2014-12-04 15:57:32 +00:00
|
|
|
\sa qDebug(), qInfo(), qWarning(), qCritical(), qInstallMessageHandler(),
|
2012-04-02 10:17:28 +00:00
|
|
|
{Debugging Techniques}
|
|
|
|
*/
|
|
|
|
|
2012-04-25 09:09:48 +00:00
|
|
|
/*!
|
|
|
|
\macro qMove(x)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
It expands to "std::move" if your compiler supports that C++11 function, or to nothing
|
|
|
|
otherwise.
|
2014-01-27 14:20:25 +00:00
|
|
|
|
|
|
|
qMove takes an rvalue reference to its parameter \a x, and converts it to an xvalue.
|
2012-04-25 09:09:48 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-06 23:54:13 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DECL_NOTHROW
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.0
|
|
|
|
|
|
|
|
This macro marks a function as never throwing, under no
|
|
|
|
circumstances. If the function does nevertheless throw, the
|
|
|
|
behaviour is undefined.
|
|
|
|
|
|
|
|
The macro expands to either "throw()", if that has some benefit on
|
|
|
|
the compiler, or to C++11 noexcept, if available, or to nothing
|
|
|
|
otherwise.
|
|
|
|
|
|
|
|
If you need C++11 noexcept semantics, don't use this macro, use
|
|
|
|
Q_DECL_NOEXCEPT/Q_DECL_NOEXCEPT_EXPR instead.
|
|
|
|
|
2014-02-01 15:30:08 +00:00
|
|
|
\sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR()
|
2012-08-06 23:54:13 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-03 08:38:00 +00:00
|
|
|
/*!
|
|
|
|
\macro QT_TERMINATE_ON_EXCEPTION(expr)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\internal
|
|
|
|
|
|
|
|
In general, use of the Q_DECL_NOEXCEPT macro is preferred over
|
|
|
|
Q_DECL_NOTHROW, because it exhibits well-defined behavior and
|
|
|
|
supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However,
|
|
|
|
use of Q_DECL_NOTHROW has the advantage that Windows builds
|
|
|
|
benefit on a wide range or compiler versions that do not yet
|
|
|
|
support the C++11 noexcept feature.
|
|
|
|
|
|
|
|
It may therefore be beneficial to use Q_DECL_NOTHROW and emulate
|
|
|
|
the C++11 behavior manually with an embedded try/catch.
|
|
|
|
|
|
|
|
Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this
|
|
|
|
purpose. It either expands to \c expr (if Qt is compiled without
|
|
|
|
exception support or the compiler supports C++11 noexcept
|
|
|
|
semantics) or to
|
|
|
|
\code
|
|
|
|
try { expr; } catch(...) { qTerminate(); }
|
2012-08-15 20:53:10 +00:00
|
|
|
\endcode
|
2012-08-03 08:38:00 +00:00
|
|
|
otherwise.
|
|
|
|
|
|
|
|
Since this macro expands to just \c expr if the compiler supports
|
|
|
|
C++11 noexcept, expecting the compiler to take over responsibility
|
|
|
|
of calling std::terminate() in that case, it should not be used
|
|
|
|
outside Q_DECL_NOTHROW functions.
|
|
|
|
|
|
|
|
\sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate()
|
|
|
|
*/
|
|
|
|
|
2012-08-06 23:54:13 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DECL_NOEXCEPT
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.0
|
|
|
|
|
|
|
|
This macro marks a function as never throwing. If the function
|
|
|
|
does nevertheless throw, the behaviour is defined:
|
|
|
|
std::terminate() is called.
|
|
|
|
|
|
|
|
The macro expands to C++11 noexcept, if available, or to nothing
|
|
|
|
otherwise.
|
|
|
|
|
|
|
|
If you need the operator version of C++11 noexcept, use
|
|
|
|
Q_DECL_NOEXCEPT_EXPR(x).
|
|
|
|
|
|
|
|
If you don't need C++11 noexcept semantics, e.g. because your
|
|
|
|
function can't possibly throw, don't use this macro, use
|
|
|
|
Q_DECL_NOTHROW instead.
|
|
|
|
|
2014-02-01 15:30:08 +00:00
|
|
|
\sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR()
|
2012-08-06 23:54:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECL_NOEXCEPT_EXPR(x)
|
|
|
|
\relates <QtGlobal>
|
|
|
|
\since 5.0
|
|
|
|
|
2014-01-27 14:20:25 +00:00
|
|
|
This macro marks a function as non-throwing if \a x is \c true. If
|
2012-08-06 23:54:13 +00:00
|
|
|
the function does nevertheless throw, the behaviour is defined:
|
|
|
|
std::terminate() is called.
|
|
|
|
|
|
|
|
The macro expands to C++11 noexcept(x), if available, or to
|
|
|
|
nothing otherwise.
|
|
|
|
|
|
|
|
If you need the always-true version of C++11 noexcept, use
|
|
|
|
Q_DECL_NOEXCEPT.
|
|
|
|
|
|
|
|
If you don't need C++11 noexcept semantics, e.g. because your
|
|
|
|
function can't possibly throw, don't use this macro, use
|
|
|
|
Q_DECL_NOTHROW instead.
|
|
|
|
|
2014-02-01 15:30:08 +00:00
|
|
|
\sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT
|
2012-08-06 23:54:13 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-10 13:30:06 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_DECL_OVERRIDE
|
|
|
|
\since 5.0
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be used to declare an overriding virtual
|
|
|
|
function. Use of this markup will allow the compiler to generate
|
|
|
|
an error if the overriding virtual function does not in fact
|
|
|
|
override anything.
|
|
|
|
|
|
|
|
It expands to "override" if your compiler supports that C++11
|
|
|
|
contextual keyword, or to nothing otherwise.
|
|
|
|
|
|
|
|
The macro goes at the end of the function, usually after the
|
|
|
|
\c{const}, if any:
|
|
|
|
\code
|
|
|
|
// generate error if this doesn't actually override anything:
|
|
|
|
virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\sa Q_DECL_FINAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_DECL_FINAL
|
|
|
|
\since 5.0
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
This macro can be used to declare an overriding virtual or a class
|
|
|
|
as "final", with Java semantics. Further-derived classes can then
|
|
|
|
no longer override this virtual function, or inherit from this
|
|
|
|
class, respectively.
|
|
|
|
|
|
|
|
It expands to "final" if your compiler supports that C++11
|
|
|
|
contextual keyword, or something non-standard if your compiler
|
|
|
|
supports something close enough to the C++11 semantics, or to
|
|
|
|
nothing otherwise.
|
|
|
|
|
|
|
|
The macro goes at the end of the function, usually after the
|
|
|
|
\c{const}, if any:
|
|
|
|
\code
|
|
|
|
// more-derived classes no longer permitted to override this:
|
|
|
|
virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_FINAL;
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
For classes, it goes in front of the \c{:} in the class
|
|
|
|
definition, if any:
|
|
|
|
\code
|
|
|
|
class QRect Q_DECL_FINAL { // cannot be derived from
|
|
|
|
// ...
|
|
|
|
};
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
\sa Q_DECL_OVERRIDE
|
|
|
|
*/
|
|
|
|
|
2013-09-02 08:12:07 +00:00
|
|
|
/*!
|
|
|
|
\macro Q_FORWARD_DECLARE_OBJC_CLASS(classname)
|
|
|
|
\since 5.2
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Forward-declares an Objective-C \a classname in a manner such that it can be
|
|
|
|
compiled as either Objective-C or C++.
|
|
|
|
|
|
|
|
This is primarily intended for use in header files that may be included by
|
|
|
|
both Objective-C and C++ source files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_FORWARD_DECLARE_CF_TYPE(type)
|
|
|
|
\since 5.2
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Forward-declares a Core Foundation \a type. This includes the actual
|
|
|
|
type and the ref type. For example, Q_FORWARD_DECLARE_CF_TYPE(CFString)
|
|
|
|
declares __CFString and CFStringRef.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\macro Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type)
|
|
|
|
\since 5.2
|
|
|
|
\relates <QtGlobal>
|
|
|
|
|
|
|
|
Forward-declares a mutable Core Foundation \a type. This includes the actual
|
2014-09-15 20:18:58 +00:00
|
|
|
type and the ref type. For example, Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(CFMutableString)
|
2013-09-02 08:12:07 +00:00
|
|
|
declares __CFMutableString and CFMutableStringRef.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|