1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qplatformdefs.h"
46 #include "qthreadstorage.h"
48 #include "qdatetime.h"
51 #include <private/qthread_p.h>
59 #ifndef QT_NO_EXCEPTIONS
64 #if !defined(Q_OS_WINCE)
66 # if defined(Q_CC_MSVC)
71 #if defined(Q_OS_VXWORKS)
75 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
76 #include <CoreServices/CoreServices.h>
81 #if !QT_DEPRECATED_SINCE(5, 0)
82 // Make sure they're defined to be exported
83 Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
84 Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
90 \brief The QFlag class is a helper data type for QFlags.
92 It is equivalent to a plain \c int, except with respect to
93 function overloading and type conversions. You should never need
94 to use this class in your applications.
100 \fn QFlag::QFlag(int value)
102 Constructs a QFlag object that stores the given \a value.
106 \fn QFlag::operator int() const
108 Returns the value stored by the QFlag object.
114 \brief The QFlags class provides a type-safe way of storing
115 OR-combinations of enum values.
120 The QFlags<Enum> class is a template class, where Enum is an enum
121 type. QFlags is used throughout Qt for storing combinations of
124 The traditional C++ approach for storing OR-combinations of enum
125 values is to use an \c int or \c uint variable. The inconvenience
126 with this approach is that there's no type checking at all; any
127 enum value can be OR'd with any other enum value and passed on to
128 a function that takes an \c int or \c uint.
130 Qt uses QFlags to provide type safety. For example, the
131 Qt::Alignment type is simply a typedef for
132 QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
133 Qt::Alignment parameter, which means that any combination of
134 Qt::AlignmentFlag values, or 0, is legal:
136 \snippet code/src_corelib_global_qglobal.cpp 0
138 If you try to pass a value from another enum or just a plain
139 integer other than 0, the compiler will report an error. If you
140 need to cast integer values to flags in a untyped fashion, you can
141 use the explicit QFlags constructor as cast operator.
143 If you want to use QFlags for your own enum types, use
144 the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
148 \snippet code/src_corelib_global_qglobal.cpp 1
150 You can then use the \c MyClass::Options type to store
151 combinations of \c MyClass::Option values.
153 \section1 Flags and the Meta-Object System
155 The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
156 system, so they cannot be used by Qt Script or edited in Qt Designer.
157 To make the flags available for these purposes, the Q_FLAGS() macro must
160 \snippet code/src_corelib_global_qglobal.cpp meta-object flags
162 \section1 Naming Convention
164 A sensible naming convention for enum types and associated QFlags
165 types is to give a singular name to the enum type (e.g., \c
166 Option) and a plural name to the QFlags type (e.g., \c Options).
167 When a singular name is desired for the QFlags type (e.g., \c
168 Alignment), you can use \c Flag as the suffix for the enum type
169 (e.g., \c AlignmentFlag).
178 Typedef for the integer type used for storage as well as for
179 implicit conversion. Either \c int or \c{unsigned int}, depending
180 on whether the enum's underlying type is signed or unsigned.
184 \typedef QFlags::enum_type
186 Typedef for the Enum template type.
190 \fn QFlags::QFlags(const QFlags &other)
192 Constructs a copy of \a other.
196 \fn QFlags::QFlags(Enum flag)
198 Constructs a QFlags object storing the given \a flag.
202 \fn QFlags::QFlags(Zero zero)
204 Constructs a QFlags object with no flags set. \a zero must be a
209 \fn QFlags::QFlags(QFlag value)
211 Constructs a QFlags object initialized with the given integer \a
214 The QFlag type is a helper type. By using it here instead of \c
215 int, we effectively ensure that arbitrary enum values cannot be
216 cast to a QFlags, whereas untyped enum values (i.e., \c int
221 \fn QFlags &QFlags::operator=(const QFlags &other)
223 Assigns \a other to this object and returns a reference to this
228 \fn QFlags &QFlags::operator&=(int mask)
230 Performs a bitwise AND operation with \a mask and stores the
231 result in this QFlags object. Returns a reference to this object.
233 \sa operator&(), operator|=(), operator^=()
237 \fn QFlags &QFlags::operator&=(uint mask)
243 \fn QFlags &QFlags::operator|=(QFlags other)
245 Performs a bitwise OR operation with \a other and stores the
246 result in this QFlags object. Returns a reference to this object.
248 \sa operator|(), operator&=(), operator^=()
252 \fn QFlags &QFlags::operator|=(Enum other)
258 \fn QFlags &QFlags::operator^=(QFlags other)
260 Performs a bitwise XOR operation with \a other and stores the
261 result in this QFlags object. Returns a reference to this object.
263 \sa operator^(), operator&=(), operator|=()
267 \fn QFlags &QFlags::operator^=(Enum other)
273 \fn QFlags::operator Int() const
275 Returns the value stored in the QFlags object as an integer.
281 \fn QFlags QFlags::operator|(QFlags other) const
283 Returns a QFlags object containing the result of the bitwise OR
284 operation on this object and \a other.
286 \sa operator|=(), operator^(), operator&(), operator~()
290 \fn QFlags QFlags::operator|(Enum other) const
296 \fn QFlags QFlags::operator^(QFlags other) const
298 Returns a QFlags object containing the result of the bitwise XOR
299 operation on this object and \a other.
301 \sa operator^=(), operator&(), operator|(), operator~()
305 \fn QFlags QFlags::operator^(Enum other) const
311 \fn QFlags QFlags::operator&(int mask) const
313 Returns a QFlags object containing the result of the bitwise AND
314 operation on this object and \a mask.
316 \sa operator&=(), operator|(), operator^(), operator~()
320 \fn QFlags QFlags::operator&(uint mask) const
326 \fn QFlags QFlags::operator&(Enum mask) const
332 \fn QFlags QFlags::operator~() const
334 Returns a QFlags object that contains the bitwise negation of
337 \sa operator&(), operator|(), operator^()
341 \fn bool QFlags::operator!() const
343 Returns true if no flag is set (i.e., if the value stored by the
344 QFlags object is 0); otherwise returns false.
348 \fn bool QFlags::testFlag(Enum flag) const
351 Returns true if the \a flag is set, otherwise false.
355 \macro Q_DISABLE_COPY(Class)
358 Disables the use of copy constructors and assignment operators
359 for the given \a Class.
361 Instances of subclasses of QObject should not be thought of as
362 values that can be copied or assigned, but as unique identities.
363 This means that when you create your own subclass of QObject
364 (director or indirect), you should \e not give it a copy constructor
365 or an assignment operator. However, it may not enough to simply
366 omit them from your class, because, if you mistakenly write some code
367 that requires a copy constructor or an assignment operator (it's easy
368 to do), your compiler will thoughtfully create it for you. You must
371 The curious user will have seen that the Qt classes derived
372 from QObject typically include this macro in a private section:
374 \snippet code/src_corelib_global_qglobal.cpp 43
376 It declares a copy constructor and an assignment operator in the
377 private section, so that if you use them by mistake, the compiler
378 will report an error.
380 \snippet code/src_corelib_global_qglobal.cpp 44
382 But even this might not catch absolutely every case. You might be
383 tempted to do something like this:
385 \snippet code/src_corelib_global_qglobal.cpp 45
387 First of all, don't do that. Most compilers will generate code that
388 uses the copy constructor, so the privacy violation error will be
389 reported, but your C++ compiler is not required to generate code for
390 this statement in a specific way. It could generate code using
391 \e{neither} the copy constructor \e{nor} the assignment operator we
392 made private. In that case, no error would be reported, but your
393 application would probably crash when you called a member function
398 \macro Q_DECLARE_FLAGS(Flags, Enum)
401 The Q_DECLARE_FLAGS() macro expands to
403 \snippet code/src_corelib_global_qglobal.cpp 2
405 \a Enum is the name of an existing enum type, whereas \a Flags is
406 the name of the QFlags<\e{Enum}> typedef.
408 See the QFlags documentation for details.
410 \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
414 \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
417 The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
418 operator|() functions for \a Flags, which is of type QFlags<T>.
420 See the QFlags documentation for details.
422 \sa Q_DECLARE_FLAGS()
426 \headerfile <QtGlobal>
427 \title Global Qt Declarations
430 \brief The <QtGlobal> header file includes the fundamental global
431 declarations. It is included by most other Qt header files.
433 The global declarations include \l{types}, \l{functions} and
436 The type definitions are partly convenience definitions for basic
437 types (some of which guarantee certain bit-sizes on all platforms
438 supported by Qt), partly types related to Qt message handling. The
439 functions are related to generating messages, Qt version handling
440 and comparing and adjusting object values. And finally, some of
441 the declared macros enable programmers to add compiler or platform
442 specific code to their applications, while others are convenience
443 macros for larger operations.
447 The header file declares several type definitions that guarantee a
448 specified bit-size on all platforms supported by Qt for various
449 basic types, for example \l qint8 which is a signed char
450 guaranteed to be 8-bit on all platforms supported by Qt. The
451 header file also declares the \l qlonglong type definition for \c
452 {long long int } (\c __int64 on Windows).
454 Several convenience type definitions are declared: \l qreal for \c
455 double, \l uchar for \c unsigned char, \l uint for \c unsigned
456 int, \l ulong for \c unsigned long and \l ushort for \c unsigned
459 Finally, the QtMsgType definition identifies the various messages
460 that can be generated and sent to a Qt message handler;
461 QtMessageHandler is a type definition for a pointer to a function with
463 \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}.
464 QMessageLogContext class contains the line, file, and function the
465 message was logged at. This information is created by the QMessageLogger
470 The <QtGlobal> header file contains several functions comparing
471 and adjusting an object's value. These functions take a template
472 type as argument: You can retrieve the absolute value of an object
473 using the qAbs() function, and you can bound a given object's
474 value by given minimum and maximum values using the qBound()
475 function. You can retrieve the minimum and maximum of two given
476 objects using qMin() and qMax() respectively. All these functions
477 return a corresponding template type; the template types can be
478 replaced by any other type.
482 \snippet code/src_corelib_global_qglobal.cpp 3
484 <QtGlobal> also contains functions that generate messages from the
485 given string argument: qCritical(), qDebug(), qFatal() and
486 qWarning(). These functions call the message handler with the
491 \snippet code/src_corelib_global_qglobal.cpp 4
493 The remaining functions are qRound() and qRound64(), which both
494 accept a \l qreal value as their argument returning the value
495 rounded up to the nearest integer and 64-bit integer respectively,
496 the qInstallMessageHandler() function which installs the given
497 QtMessageHandler, and the qVersion() function which returns the
498 version number of Qt at run-time as a string.
502 The <QtGlobal> header file provides a range of macros (Q_CC_*)
503 that are defined if the application is compiled using the
504 specified platforms. For example, the Q_CC_SUN macro is defined if
505 the application is compiled using Forte Developer, or Sun Studio
506 C++. The header file also declares a range of macros (Q_OS_*)
507 that are defined for the specified platforms. For example,
508 Q_OS_X11 which is defined for the X Window System.
510 The purpose of these macros is to enable programmers to add
511 compiler or platform specific code to their application.
513 The remaining macros are convenience macros for larger operations:
514 The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the
515 possibility of marking text for dynamic translation,
516 i.e. translation without changing the stored source text. The
517 Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
518 level of refinement. The Q_FOREACH() and foreach() macros
519 implement Qt's foreach loop.
521 The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
522 64-bit integer literals in a platform-independent way. The
523 Q_CHECK_PTR() macro prints a warning containing the source code's
524 file name and line number, saying that the program ran out of
525 memory, if the pointer is 0. The qPrintable() macro represent an
526 easy way of printing text.
528 Finally, the QT_POINTER_SIZE macro expands to the size of a
529 pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
530 expand to a numeric value or a string, respectively, specifying
531 Qt's version number, i.e the version the application is compiled
534 \sa <QtAlgorithms>, QSysInfo
541 Typedef for \c double on all platforms except for those using CPUs with
543 On ARM-based platforms, \c qreal is a typedef for \c float for performance
550 Convenience typedef for \c{unsigned char}.
556 Convenience typedef for \c{unsigned short}.
562 Convenience typedef for \c{unsigned int}.
568 Convenience typedef for \c{unsigned long}.
574 Typedef for \c{signed char}. This type is guaranteed to be 8-bit
575 on all platforms supported by Qt.
582 Typedef for \c{unsigned char}. This type is guaranteed to
583 be 8-bit on all platforms supported by Qt.
589 Typedef for \c{signed short}. This type is guaranteed to be
590 16-bit on all platforms supported by Qt.
597 Typedef for \c{unsigned short}. This type is guaranteed to
598 be 16-bit on all platforms supported by Qt.
604 Typedef for \c{signed int}. This type is guaranteed to be 32-bit
605 on all platforms supported by Qt.
612 Typedef for \c{unsigned int}. This type is guaranteed to
613 be 32-bit on all platforms supported by Qt.
619 Typedef for \c{long long int} (\c __int64 on Windows). This type
620 is guaranteed to be 64-bit on all platforms supported by Qt.
622 Literals of this type can be created using the Q_INT64_C() macro:
624 \snippet code/src_corelib_global_qglobal.cpp 5
626 \sa Q_INT64_C(), quint64, qlonglong
633 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
634 Windows). This type is guaranteed to be 64-bit on all platforms
637 Literals of this type can be created using the Q_UINT64_C()
640 \snippet code/src_corelib_global_qglobal.cpp 6
642 \sa Q_UINT64_C(), qint64, qulonglong
649 Integral type for representing a pointers (useful for hashing,
652 Typedef for either quint32 or quint64. This type is guaranteed to
653 be the same size as a pointer on all platforms supported by Qt. On
654 a system with 32-bit pointers, quintptr is a typedef for quint32;
655 on a system with 64-bit pointers, quintptr is a typedef for
658 Note that quintptr is unsigned. Use qptrdiff for signed values.
660 \sa qptrdiff, quint32, quint64
667 Integral type for representing pointer differences.
669 Typedef for either qint32 or qint64. This type is guaranteed to be
670 the same size as a pointer on all platforms supported by Qt. On a
671 system with 32-bit pointers, quintptr is a typedef for quint32; on
672 a system with 64-bit pointers, quintptr is a typedef for quint64.
674 Note that qptrdiff is signed. Use quintptr for unsigned values.
676 \sa quintptr, qint32, qint64
683 This enum describes the messages that can be sent to a message
684 handler (QtMsgHandler). You can use the enum to identify and
685 associate the various message types with the appropriate
689 A message generated by the qDebug() function.
691 A message generated by the qWarning() function.
693 A message generated by the qCritical() function.
695 A message generated by the qFatal() function.
699 \sa QtMessageHandler, qInstallMessageHandler()
702 /*! \typedef QFunctionPointer
705 This is a typedef for \c{void (*)()}, a pointer to a function that takes
706 no arguments and returns void.
709 /*! \macro qint64 Q_INT64_C(literal)
712 Wraps the signed 64-bit integer \a literal in a
713 platform-independent way.
717 \snippet code/src_corelib_global_qglobal.cpp 8
719 \sa qint64, Q_UINT64_C()
722 /*! \macro quint64 Q_UINT64_C(literal)
725 Wraps the unsigned 64-bit integer \a literal in a
726 platform-independent way.
730 \snippet code/src_corelib_global_qglobal.cpp 9
732 \sa quint64, Q_INT64_C()
735 /*! \typedef qlonglong
738 Typedef for \c{long long int} (\c __int64 on Windows). This is
739 the same as \l qint64.
741 \sa qulonglong, qint64
748 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
749 Windows). This is the same as \l quint64.
751 \sa quint64, qlonglong
754 /*! \fn T qAbs(const T &value)
757 Compares \a value to the 0 of type T and returns the absolute
758 value. Thus if T is \e {double}, then \a value is compared to
763 \snippet code/src_corelib_global_qglobal.cpp 10
766 /*! \fn int qRound(qreal value)
769 Rounds \a value to the nearest integer.
773 \snippet code/src_corelib_global_qglobal.cpp 11
776 /*! \fn qint64 qRound64(qreal value)
779 Rounds \a value to the nearest 64-bit integer.
783 \snippet code/src_corelib_global_qglobal.cpp 12
786 /*! \fn const T &qMin(const T &value1, const T &value2)
789 Returns the minimum of \a value1 and \a value2.
793 \snippet code/src_corelib_global_qglobal.cpp 13
798 /*! \fn const T &qMax(const T &value1, const T &value2)
801 Returns the maximum of \a value1 and \a value2.
805 \snippet code/src_corelib_global_qglobal.cpp 14
810 /*! \fn const T &qBound(const T &min, const T &value, const T &max)
813 Returns \a value bounded by \a min and \a max. This is equivalent
814 to qMax(\a min, qMin(\a value, \a max)).
818 \snippet code/src_corelib_global_qglobal.cpp 15
824 \macro QT_VERSION_CHECK
827 Turns the major, minor and patch numbers of a version into an
828 integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
829 be compared with another similarly processed version id.
838 This macro expands a numeric value of the form 0xMMNNPP (MM =
839 major, NN = minor, PP = patch) that specifies Qt's version
840 number. For example, if you compile your application against Qt
841 4.1.2, the QT_VERSION macro will expand to 0x040102.
843 You can use QT_VERSION to use the latest Qt features where
848 \snippet code/src_corelib_global_qglobal.cpp 16
850 \sa QT_VERSION_STR, qVersion()
854 \macro QT_VERSION_STR
857 This macro expands to a string that specifies Qt's version number
858 (for example, "4.1.2"). This is the version against which the
859 application is compiled.
861 \sa qVersion(), QT_VERSION
867 Returns the version number of Qt at run-time as a string (for
868 example, "4.1.2"). This may be a different version than the
869 version the application was compiled against.
874 const char *qVersion() Q_DECL_NOTHROW
876 return QT_VERSION_STR;
879 bool qSharedBuild() Q_DECL_NOTHROW
888 /*****************************************************************************
889 System detection routines
890 *****************************************************************************/
895 \brief The QSysInfo class provides information about the system.
898 \li \l WordSize specifies the size of a pointer for the platform
899 on which the application is compiled.
900 \li \l ByteOrder specifies whether the platform is big-endian or
902 \li \l WindowsVersion specifies the version of the Windows operating
903 system on which the application is run (Windows only)
904 \li \l MacintoshVersion specifies the version of the Macintosh
905 operating system on which the application is run (Mac only).
908 Some constants are defined only on certain platforms. You can use
909 the preprocessor symbols Q_OS_WIN and Q_OS_MAC to test that
910 the application is compiled under Windows or Mac.
916 \enum QSysInfo::Sizes
918 This enum provides platform-specific information about the sizes of data
919 structures used by the underlying architecture.
921 \value WordSize The size in bits of a pointer for the platform on which
922 the application is compiled (32 or 64).
926 \variable QSysInfo::WindowsVersion
927 \brief the version of the Windows operating system on which the
928 application is run (Windows only)
932 \fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
935 Returns the version of the Windows operating system on which the
936 application is run (Windows only).
940 \variable QSysInfo::MacintoshVersion
941 \brief the version of the Macintosh operating system on which
942 the application is run (Mac only).
946 \fn QSysInfo::MacVersion QSysInfo::macVersion()
948 Returns the version of Mac OS X on which the application is run (Mac OS X
953 \enum QSysInfo::Endian
955 \value BigEndian Big-endian byte order (also called Network byte order)
956 \value LittleEndian Little-endian byte order
957 \value ByteOrder Equals BigEndian or LittleEndian, depending on
958 the platform's byte order.
962 \enum QSysInfo::WinVersion
964 This enum provides symbolic names for the various versions of the
965 Windows operating system. On Windows, the
966 QSysInfo::WindowsVersion variable gives the version of the system
967 on which the application is run.
969 MS-DOS-based versions:
971 \value WV_32s Windows 3.1 with Win 32s
972 \value WV_95 Windows 95
973 \value WV_98 Windows 98
974 \value WV_Me Windows Me
976 NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
978 \value WV_NT Windows NT (operating system version 4.0)
979 \value WV_2000 Windows 2000 (operating system version 5.0)
980 \value WV_XP Windows XP (operating system version 5.1)
981 \value WV_2003 Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
982 \value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
983 \value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
984 \value WV_WINDOWS8 Windows 8 (operating system version 6.2)
986 Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
988 \value WV_4_0 Operating system version 4.0, corresponds to Windows NT
989 \value WV_5_0 Operating system version 5.0, corresponds to Windows 2000
990 \value WV_5_1 Operating system version 5.1, corresponds to Windows XP
991 \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
992 \value WV_6_0 Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
993 \value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
994 \value WV_6_2 Operating system version 6.2, corresponds to Windows 8
998 \value WV_CE Windows CE
999 \value WV_CENET Windows CE .NET
1000 \value WV_CE_5 Windows CE 5.x
1001 \value WV_CE_6 Windows CE 6.x
1003 The following masks can be used for testing whether a Windows
1004 version is MS-DOS-based, NT-based, or CE-based:
1006 \value WV_DOS_based MS-DOS-based version of Windows
1007 \value WV_NT_based NT-based version of Windows
1008 \value WV_CE_based CE-based version of Windows
1014 \enum QSysInfo::MacVersion
1016 This enum provides symbolic names for the various versions of the
1017 Macintosh operating system. On Mac, the
1018 QSysInfo::MacintoshVersion variable gives the version of the
1019 system on which the application is run.
1021 \value MV_9 Mac OS 9 (unsupported)
1022 \value MV_10_0 Mac OS X 10.0 (unsupported)
1023 \value MV_10_1 Mac OS X 10.1 (unsupported)
1024 \value MV_10_2 Mac OS X 10.2 (unsupported)
1025 \value MV_10_3 Mac OS X 10.3
1026 \value MV_10_4 Mac OS X 10.4
1027 \value MV_10_5 Mac OS X 10.5
1028 \value MV_10_6 Mac OS X 10.6
1029 \value MV_10_7 Mac OS X 10.7
1030 \value MV_10_8 Mac OS X 10.8
1031 \value MV_Unknown An unknown and currently unsupported platform
1033 \value MV_CHEETAH Apple codename for MV_10_0
1034 \value MV_PUMA Apple codename for MV_10_1
1035 \value MV_JAGUAR Apple codename for MV_10_2
1036 \value MV_PANTHER Apple codename for MV_10_3
1037 \value MV_TIGER Apple codename for MV_10_4
1038 \value MV_LEOPARD Apple codename for MV_10_5
1039 \value MV_SNOWLEOPARD Apple codename for MV_10_6
1040 \value MV_LION Apple codename for MV_10_7
1041 \value MV_MOUNTAINLION Apple codename for MV_10_8
1050 Defined on Darwin OS (synonym for Q_OS_MAC).
1057 Defined on all supported versions of Windows.
1064 Defined on Windows CE.
1078 Defined on Sun Solaris.
1092 Defined on DEC Ultrix.
1134 Defined on SGI Irix.
1141 Defined on HP Tru64 UNIX.
1148 Defined on SCO OpenServer 5.
1152 \macro Q_OS_UNIXWARE
1155 Defined on UnixWare 7, Open UNIX 8.
1169 Defined on GNU Hurd.
1183 Defined on Reliant UNIX.
1190 Defined on DYNIX/ptx.
1197 Defined on QNX Neutrino.
1211 Defined on Any BSD 4.4 system.
1218 Defined on Any UNIX BSD/SYSV system.
1225 Defined if the application is compiled using Digital Mars C/C++
1226 (used to be Symantec C++).
1233 Defined if the application is compiled using Microsoft Visual
1234 C/C++, Intel C++ for Windows.
1241 Defined if the application is compiled using Borland/Turbo C++.
1248 Defined if the application is compiled using Watcom C++.
1255 Defined if the application is compiled using GNU C++.
1262 Defined if the application is compiled using Comeau C++.
1269 Defined if the application is compiled using Edison Design Group
1277 Defined if the application is compiled using CenterLine C++.
1284 Defined if the application is compiled using Forte Developer, or
1292 Defined if the application is compiled using MIPSpro C++.
1299 Defined if the application is compiled using DEC C++.
1306 Defined if the application is compiled using HP aC++.
1313 Defined if the application is compiled using SCO OUDK and UDK.
1320 Defined if the application is compiled using Reliant C++.
1327 Defined if the application is compiled using KAI C++.
1334 Defined if the application is compiled using Intel C++ for Linux,
1335 Intel C++ for Windows.
1342 Defined if the application is compiled using MetaWare High C/C++.
1349 Defined if the application is compiled using Portland Group C++.
1356 Defined if the application is compiled using Green Hills
1357 Optimizing C++ Compilers.
1364 Defined on MAC OS (synonym for Darwin).
1368 \macro Q_PROCESSOR_ALPHA
1371 Defined if the application is compiled for Alpha processors.
1375 \macro Q_PROCESSOR_ARM
1378 Defined if the application is compiled for ARM processors. Qt currently
1379 supports three optional ARM revisions: \l Q_PROCESSOR_ARM_V5, \l
1380 Q_PROCESSOR_ARM_V6, and \l Q_PROCESSOR_ARM_V7.
1383 \macro Q_PROCESSOR_ARM_V5
1386 Defined if the application is compiled for ARMv5 processors. The \l
1387 Q_PROCESSOR_ARM macro is also defined when Q_PROCESSOR_ARM_V5 is defined.
1390 \macro Q_PROCESSOR_ARM_V6
1393 Defined if the application is compiled for ARMv6 processors. The \l
1394 Q_PROCESSOR_ARM and \l Q_PROCESSOR_ARM_V5 macros are also defined when
1395 Q_PROCESSOR_ARM_V6 is defined.
1398 \macro Q_PROCESSOR_ARM_V7
1401 Defined if the application is compiled for ARMv7 processors. The \l
1402 Q_PROCESSOR_ARM, \l Q_PROCESSOR_ARM_V5, and \l Q_PROCESSOR_ARM_V6 macros
1403 are also defined when Q_PROCESSOR_ARM_V7 is defined.
1407 \macro Q_PROCESSOR_AVR32
1410 Defined if the application is compiled for AVR32 processors.
1414 \macro Q_PROCESSOR_BLACKFIN
1417 Defined if the application is compiled for Blackfin processors.
1421 \macro Q_PROCESSOR_IA64
1424 Defined if the application is compiled for IA-64 processors. This includes
1425 all Itanium and Itanium 2 processors.
1429 \macro Q_PROCESSOR_MIPS
1432 Defined if the application is compiled for MIPS processors. Qt currently
1433 supports seven MIPS revisions: \l Q_PROCESSOR_MIPS_I, \l
1434 Q_PROCESSOR_MIPS_II, \l Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, \l
1435 Q_PROCESSOR_MIPS_V, \l Q_PROCESSOR_MIPS_32, and \l Q_PROCESSOR_MIPS_64.
1438 \macro Q_PROCESSOR_MIPS_I
1441 Defined if the application is compiled for MIPS-I processors. The \l
1442 Q_PROCESSOR_MIPS macro is also defined when Q_PROCESSOR_MIPS_I is defined.
1445 \macro Q_PROCESSOR_MIPS_II
1448 Defined if the application is compiled for MIPS-II processors. The \l
1449 Q_PROCESSOR_MIPS and \l Q_PROCESSOR_MIPS_I macros are also defined when
1450 Q_PROCESSOR_MIPS_II is defined.
1453 \macro Q_PROCESSOR_MIPS_32
1456 Defined if the application is compiled for MIPS32 processors. The \l
1457 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
1458 are also defined when Q_PROCESSOR_MIPS_32 is defined.
1461 \macro Q_PROCESSOR_MIPS_III
1464 Defined if the application is compiled for MIPS-III processors. The \l
1465 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
1466 are also defined when Q_PROCESSOR_MIPS_III is defined.
1469 \macro Q_PROCESSOR_MIPS_IV
1472 Defined if the application is compiled for MIPS-IV processors. The \l
1473 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, and \l
1474 Q_PROCESSOR_MIPS_III macros are also defined when Q_PROCESSOR_MIPS_IV is
1478 \macro Q_PROCESSOR_MIPS_V
1481 Defined if the application is compiled for MIPS-V processors. The \l
1482 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
1483 Q_PROCESSOR_MIPS_III, and \l Q_PROCESSOR_MIPS_IV macros are also defined
1484 when Q_PROCESSOR_MIPS_V is defined.
1487 \macro Q_PROCESSOR_MIPS_64
1490 Defined if the application is compiled for MIPS64 processors. The \l
1491 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
1492 Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, and \l Q_PROCESSOR_MIPS_V
1493 macros are also defined when Q_PROCESSOR_MIPS_64 is defined.
1497 \macro Q_PROCESSOR_POWER
1500 Defined if the application is compiled for POWER processors. Qt currently
1501 supports two Power variants: \l Q_PROCESSOR_POWER_32 and \l
1502 Q_PROCESSOR_POWER_64.
1505 \macro Q_PROCESSOR_POWER_32
1508 Defined if the application is compiled for 32-bit Power processors. The \l
1509 Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_32 is
1513 \macro Q_PROCESSOR_POWER_64
1516 Defined if the application is compiled for 64-bit Power processors. The \l
1517 Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_64 is
1522 \macro Q_PROCESSOR_S390
1525 Defined if the application is compiled for S/390 processors. Qt supports
1526 one optional variant of S/390: Q_PROCESSOR_S390_X.
1529 \macro Q_PROCESSOR_S390_X
1532 Defined if the application is compiled for S/390x processors. The \l
1533 Q_PROCESSOR_S390 macro is also defined when Q_PROCESSOR_S390_X is defined.
1537 \macro Q_PROCESSOR_SH
1540 Defined if the application is compiled for SuperH processors. Qt currently
1541 supports one SuperH revision: \l Q_PROCESSOR_SH_4A.
1544 \macro Q_PROCESSOR_SH_4A
1547 Defined if the application is compiled for SuperH 4A processors. The \l
1548 Q_PROCESSOR_SH macro is also defined when Q_PROCESSOR_SH_4A is defined.
1552 \macro Q_PROCESSOR_SPARC
1555 Defined if the application is compiled for SPARC processors. Qt currently
1556 supports one optional SPARC revision: \l Q_PROCESSOR_SPARC_V9.
1559 \macro Q_PROCESSOR_SPARC_V9
1562 Defined if the application is compiled for SPARC V9 processors. The \l
1563 Q_PROCESSOR_SPARC macro is also defined when Q_PROCESSOR_SPARC_V9 is
1568 \macro Q_PROCESSOR_X86
1571 Defined if the application is compiled for x86 processors. Qt currently
1572 supports two x86 variants: \l Q_PROCESSOR_X86_32 and \l Q_PROCESSOR_X86_64.
1575 \macro Q_PROCESSOR_X86_32
1578 Defined if the application is compiled for 32-bit x86 processors. This
1579 includes all i386, i486, i586, and i686 processors. The \l Q_PROCESSOR_X86
1580 macro is also defined when Q_PROCESSOR_X86_32 is defined.
1583 \macro Q_PROCESSOR_X86_64
1586 Defined if the application is compiled for 64-bit x86 processors. This
1587 includes all AMD64, Intel 64, and other x86_64/x64 processors. The \l
1588 Q_PROCESSOR_X86 macro is also defined when Q_PROCESSOR_X86_64 is defined.
1592 \macro QT_DISABLE_DEPRECATED_BEFORE
1595 This macro can be defined in the project file to disable functions deprecated in
1596 a specified version of Qt or any earlier version. The default version number is 5.0,
1597 meaning that functions deprecated in or before Qt 5.0 will not be included.
1600 When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to
1601 disable functions deprecated in Qt 5.1 and earlier. In any release, set
1602 QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones
1603 deprecated in Qt 5.0
1606 #if defined(QT_BUILD_QMAKE)
1607 // needed to bootstrap qmake
1608 static const unsigned int qt_one = 1;
1609 const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
1612 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
1614 QT_BEGIN_INCLUDE_NAMESPACE
1615 #include "private/qcore_mac_p.h"
1616 #include "qnamespace.h"
1617 QT_END_INCLUDE_NAMESPACE
1619 Q_CORE_EXPORT OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
1621 return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
1624 Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1)
1628 CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
1631 Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
1632 return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
1634 #endif // defined(Q_OS_MAC) && !defined(Q_OS_IOS)
1636 #if defined(Q_OS_MAC)
1638 QSysInfo::MacVersion QSysInfo::macVersion()
1641 SInt32 gestalt_version;
1642 if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
1643 return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);
1646 return QSysInfo::MV_Unknown;
1648 const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion();
1650 #elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE)
1652 QT_BEGIN_INCLUDE_NAMESPACE
1653 #include "qt_windows.h"
1654 QT_END_INCLUDE_NAMESPACE
1656 QSysInfo::WinVersion QSysInfo::windowsVersion()
1658 #ifndef VER_PLATFORM_WIN32s
1659 #define VER_PLATFORM_WIN32s 0
1661 #ifndef VER_PLATFORM_WIN32_WINDOWS
1662 #define VER_PLATFORM_WIN32_WINDOWS 1
1664 #ifndef VER_PLATFORM_WIN32_NT
1665 #define VER_PLATFORM_WIN32_NT 2
1667 #ifndef VER_PLATFORM_WIN32_CE
1668 #define VER_PLATFORM_WIN32_CE 3
1671 static QSysInfo::WinVersion winver;
1674 winver = QSysInfo::WV_NT;
1675 OSVERSIONINFO osver;
1676 osver.dwOSVersionInfoSize = sizeof(osver);
1677 GetVersionEx(&osver);
1680 qt_cever = osver.dwMajorVersion * 100;
1681 qt_cever += osver.dwMinorVersion * 10;
1683 switch (osver.dwPlatformId) {
1684 case VER_PLATFORM_WIN32s:
1685 winver = QSysInfo::WV_32s;
1687 case VER_PLATFORM_WIN32_WINDOWS:
1688 // We treat Windows Me (minor 90) the same as Windows 98
1689 if (osver.dwMinorVersion == 90)
1690 winver = QSysInfo::WV_Me;
1691 else if (osver.dwMinorVersion == 10)
1692 winver = QSysInfo::WV_98;
1694 winver = QSysInfo::WV_95;
1697 case VER_PLATFORM_WIN32_CE:
1698 if (qt_cever >= 600)
1699 winver = QSysInfo::WV_CE_6;
1700 if (qt_cever >= 500)
1701 winver = QSysInfo::WV_CE_5;
1702 else if (qt_cever >= 400)
1703 winver = QSysInfo::WV_CENET;
1705 winver = QSysInfo::WV_CE;
1708 default: // VER_PLATFORM_WIN32_NT
1709 if (osver.dwMajorVersion < 5) {
1710 winver = QSysInfo::WV_NT;
1711 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) {
1712 winver = QSysInfo::WV_2000;
1713 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) {
1714 winver = QSysInfo::WV_XP;
1715 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2) {
1716 winver = QSysInfo::WV_2003;
1717 } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0) {
1718 winver = QSysInfo::WV_VISTA;
1719 } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1) {
1720 winver = QSysInfo::WV_WINDOWS7;
1721 } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2) {
1722 winver = QSysInfo::WV_WINDOWS8;
1724 qWarning("Qt: Untested Windows version %d.%d detected!",
1725 int(osver.dwMajorVersion), int(osver.dwMinorVersion));
1726 winver = QSysInfo::WV_NT_based;
1732 QByteArray override = qgetenv("QT_WINVER_OVERRIDE");
1733 if (override.isEmpty())
1736 if (override == "Me")
1737 winver = QSysInfo::WV_Me;
1738 if (override == "95")
1739 winver = QSysInfo::WV_95;
1740 else if (override == "98")
1741 winver = QSysInfo::WV_98;
1742 else if (override == "NT")
1743 winver = QSysInfo::WV_NT;
1744 else if (override == "2000")
1745 winver = QSysInfo::WV_2000;
1746 else if (override == "2003")
1747 winver = QSysInfo::WV_2003;
1748 else if (override == "XP")
1749 winver = QSysInfo::WV_XP;
1750 else if (override == "VISTA")
1751 winver = QSysInfo::WV_VISTA;
1752 else if (override == "WINDOWS7")
1753 winver = QSysInfo::WV_WINDOWS7;
1754 else if (override == "WINDOWS8")
1755 winver = QSysInfo::WV_WINDOWS8;
1762 const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
1767 \macro void Q_ASSERT(bool test)
1770 Prints a warning message containing the source code file name and
1771 line number if \a test is false.
1773 Q_ASSERT() is useful for testing pre- and post-conditions
1774 during development. It does nothing if \c QT_NO_DEBUG was defined
1779 \snippet code/src_corelib_global_qglobal.cpp 17
1781 If \c b is zero, the Q_ASSERT statement will output the following
1782 message using the qFatal() function:
1784 \snippet code/src_corelib_global_qglobal.cpp 18
1786 \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
1790 \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
1793 Prints the message \a what together with the location \a where,
1794 the source file name and line number if \a test is false.
1796 Q_ASSERT_X is useful for testing pre- and post-conditions during
1797 development. It does nothing if \c QT_NO_DEBUG was defined during
1802 \snippet code/src_corelib_global_qglobal.cpp 19
1804 If \c b is zero, the Q_ASSERT_X statement will output the following
1805 message using the qFatal() function:
1807 \snippet code/src_corelib_global_qglobal.cpp 20
1809 \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
1813 \macro void Q_ASSUME(bool expr)
1817 Causes the compiler to assume that \a expr is true. This macro is useful
1818 for improving code generation, by providing the compiler with hints about
1819 conditions that it would not otherwise know about. However, there is no
1820 guarantee that the compiler will actually use those hints.
1822 This macro could be considered a "lighter" version of \l{Q_ASSERT}. While
1823 Q_ASSERT will abort the program's execution if the condition is false,
1824 Q_ASSUME will tell the compiler not to generate code for those conditions.
1825 Therefore, it is important that the assumptions always hold, otherwise
1826 undefined behaviour may occur.
1828 If \a expr is a constantly false condition, Q_ASSUME will tell the compiler
1829 that the current code execution cannot be reached. That is, Q_ASSUME(false)
1830 is equivalent to Q_UNREACHABLE().
1832 \note Q_LIKELY() tells the compiler that the expression is likely, but not
1833 the only possibility. Q_ASSUME tells the compiler that it is the only
1836 \sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
1840 \macro void Q_UNREACHABLE()
1844 Tells the compiler that the current point cannot be reached by any
1845 execution, so it may optimize any code paths leading here as dead code, as
1846 well as code continuing from here.
1848 This macro is useful to mark impossible conditions. For example, given the
1851 \snippet code/src_corelib_global_qglobal.cpp qunreachable-enum
1853 One can write a switch table like so:
1855 \snippet code/src_corelib_global_qglobal.cpp qunreachable-switch
1857 The advantage of inserting Q_UNREACHABLE() at that point is that the
1858 compiler is told not to generate code for a shape variable containing that
1859 value. If the macro is missing, the compiler will still generate the
1860 necessary comparisons for that value. If the case label were removed, some
1861 compilers could produce a warning that some enum values were not checked.
1863 By using this macro in impossible conditions, code coverage may be improved
1864 as dead code paths may be eliminated.
1866 \sa Q_ASSERT(), Q_ASSUME(), qFatal()
1870 \macro void Q_CHECK_PTR(void *pointer)
1873 If \a pointer is 0, prints a warning message containing the source
1874 code's file name and line number, saying that the program ran out
1877 Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during
1882 \snippet code/src_corelib_global_qglobal.cpp 21
1884 \sa qWarning(), {Debugging Techniques}
1888 \fn T *q_check_ptr(T *pointer)
1891 Uses Q_CHECK_PTR on \a pointer, then returns \a pointer.
1893 This can be used as an inline version of Q_CHECK_PTR.
1897 \macro const char* Q_FUNC_INFO()
1900 Expands to a string that describe the function the macro resides in. How this string looks
1901 more specifically is compiler dependent. With GNU GCC it is typically the function signature,
1902 while with other compilers it might be the line and column number.
1904 Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
1906 \snippet code/src_corelib_global_qglobal.cpp 22
1908 when instantiated with the integer type, will with the GCC compiler produce:
1910 \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
1912 If this macro is used outside a function, the behavior is undefined.
1916 The Q_CHECK_PTR macro calls this function if an allocation check
1919 void qt_check_pointer(const char *n, int l)
1921 qFatal("In file %s, line %d: Out of memory", n, l);
1926 Allows you to throw an exception without including <new>
1927 Called internally from Q_CHECK_PTR on certain OS combinations
1931 QT_THROW(std::bad_alloc());
1934 #ifndef QT_NO_EXCEPTIONS
1937 Allows you to call std::terminate() without including <exception>.
1938 Called internally from QT_TERMINATE_ON_EXCEPTION
1940 Q_NORETURN void qTerminate() Q_DECL_NOTHROW
1947 The Q_ASSERT macro calls this function when the test fails.
1949 void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW
1951 qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
1955 The Q_ASSERT_X macro calls this function when the test fails.
1957 void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW
1959 qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
1964 Dijkstra's bisection algorithm to find the square root of an integer.
1965 Deliberately not exported as part of the Qt API, but used in both
1966 qsimplerichtext.cpp and qgfxraster_qws.cpp
1968 Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
1970 // n must be in the range 0...UINT_MAX/2-1
1971 if (n >= (UINT_MAX>>2)) {
1972 unsigned int r = 2 * qt_int_sqrt(n / 4);
1973 unsigned int r2 = r + 1;
1974 return (n >= r2 * r2) ? r2 : r;
1976 uint h, p= 0, q= 1, r= n;
1991 void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
1992 void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
1994 #if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \
1995 defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
1997 // There are two incompatible versions of strerror_r:
1998 // a) the XSI/POSIX.1 version, which returns an int,
1999 // indicating success or not
2000 // b) the GNU version, which returns a char*, which may or may not
2001 // be the beginning of the buffer we used
2002 // The GNU libc manpage for strerror_r says you should use the XSI
2003 // version in portable code. However, it's impossible to do that if
2004 // _GNU_SOURCE is defined so we use C++ overloading to decide what to do
2005 // depending on the return type
2006 static inline QString fromstrerror_helper(int, const QByteArray &buf)
2008 return QString::fromLocal8Bit(buf);
2010 static inline QString fromstrerror_helper(const char *str, const QByteArray &)
2012 return QString::fromLocal8Bit(str);
2017 QString qt_error_string(int errorCode)
2021 if (errorCode == -1) {
2022 #if defined(Q_OS_WIN)
2023 errorCode = GetLastError();
2028 switch (errorCode) {
2032 s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
2035 s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
2038 s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
2041 s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
2045 wchar_t *string = 0;
2046 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
2049 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
2053 ret = QString::fromWCharArray(string);
2054 LocalFree((HLOCAL)string);
2056 if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
2057 ret = QString::fromLatin1("The specified module could not be found.");
2058 #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
2059 QByteArray buf(1024, '\0');
2060 ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
2062 ret = QString::fromLocal8Bit(strerror(errorCode));
2067 // ######## this breaks moc build currently
2068 // ret = QCoreApplication::translate("QIODevice", s);
2069 ret = QString::fromLatin1(s);
2070 return ret.trimmed();
2073 // getenv is declared as deprecated in VS2005. This function
2074 // makes use of the new secure getenv function.
2078 Returns the value of the environment variable with name \a
2079 varName. To get the variable string, use QByteArray::constData().
2081 \note qgetenv() was introduced because getenv() from the standard
2082 C library was deprecated in VC2005 (and later versions). qgetenv()
2083 uses the new replacement function in VC, and calls the standard C
2084 library's implementation on all other platforms.
2088 QByteArray qgetenv(const char *varName)
2090 #if defined(_MSC_VER) && _MSC_VER >= 1400
2091 size_t requiredSize = 0;
2093 getenv_s(&requiredSize, 0, 0, varName);
2094 if (requiredSize == 0)
2096 buffer.resize(int(requiredSize));
2097 getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
2098 // requiredSize includes the terminating null, which we don't want.
2099 Q_ASSERT(buffer.endsWith('\0'));
2103 return QByteArray(::getenv(varName));
2111 This function checks whether the environment variable \a varName
2116 qgetenv(varName).isEmpty()
2118 except that it's potentially much faster, and can't throw exceptions.
2120 \sa qgetenv(), qEnvironmentVariableIsSet()
2122 bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT
2124 #if defined(_MSC_VER) && _MSC_VER >= 1400
2125 // we provide a buffer that can only hold the empty string, so
2126 // when the env.var isn't empty, we'll get an ERANGE error (buffer
2130 return getenv_s(&dummy, &buffer, 1, varName) != ERANGE;
2132 const char * const value = ::getenv(varName);
2133 return !value || !*value;
2141 This function checks whether the environment variable \a varName
2146 !qgetenv(varName).isNull()
2148 except that it's potentially much faster, and can't throw exceptions.
2150 \sa qgetenv(), qEnvironmentVariableIsEmpty()
2152 bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT
2154 #if defined(_MSC_VER) && _MSC_VER >= 1400
2155 size_t requiredSize = 0;
2156 (void)getenv_s(&requiredSize, 0, 0, varName);
2157 return requiredSize != 0;
2159 return ::getenv(varName) != 0;
2166 This function sets the \a value of the environment variable named
2167 \a varName. It will create the variable if it does not exist. It
2168 returns 0 if the variable could not be set.
2170 \note qputenv() was introduced because putenv() from the standard
2171 C library was deprecated in VC2005 (and later versions). qputenv()
2172 uses the replacement function in VC, and calls the standard C
2173 library's implementation on all other platforms.
2177 bool qputenv(const char *varName, const QByteArray& value)
2179 #if defined(_MSC_VER) && _MSC_VER >= 1400
2180 return _putenv_s(varName, value.constData()) == 0;
2181 #elif defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L
2182 // POSIX.1-2001 has setenv
2183 return setenv(varName, value.constData(), true) == 0;
2185 QByteArray buffer(varName);
2188 char* envVar = qstrdup(buffer.constData());
2189 int result = putenv(envVar);
2190 if (result != 0) // error. we have to delete the string.
2196 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
2198 # if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
2199 // older versions of INTEGRITY used a long instead of a uint for the seed.
2200 typedef long SeedStorageType;
2202 typedef uint SeedStorageType;
2205 typedef QThreadStorage<SeedStorageType *> SeedStorage;
2206 Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value
2214 Thread-safe version of the standard C++ \c srand() function.
2216 Sets the argument \a seed to be used to generate a new random number sequence of
2217 pseudo random integers to be returned by qrand().
2219 The sequence of random numbers generated is deterministic per thread. For example,
2220 if two threads call qsrand(1) and subsequently calls qrand(), the threads will get
2221 the same random number sequence.
2225 void qsrand(uint seed)
2227 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
2228 SeedStorage *seedStorage = randTLS();
2230 SeedStorageType *pseed = seedStorage->localData();
2232 seedStorage->setLocalData(pseed = new SeedStorageType);
2235 //global static seed storage should always exist,
2236 //except after being deleted by QGlobalStaticDeleter.
2237 //But since it still can be called from destructor of another
2238 //global static object, fallback to srand(seed)
2242 // On Windows srand() and rand() already use Thread-Local-Storage
2243 // to store the seed between calls
2244 // this is also valid for QT_NO_THREAD
2253 Thread-safe version of the standard C++ \c rand() function.
2255 Returns a value between 0 and \c RAND_MAX (defined in \c <cstdlib> and
2256 \c <stdlib.h>), the next number in the current sequence of pseudo-random
2259 Use \c qsrand() to initialize the pseudo-random number generator with
2266 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0)
2267 SeedStorage *seedStorage = randTLS();
2269 SeedStorageType *pseed = seedStorage->localData();
2271 seedStorage->setLocalData(pseed = new SeedStorageType);
2274 return rand_r(pseed);
2276 //global static seed storage should always exist,
2277 //except after being deleted by QGlobalStaticDeleter.
2278 //But since it still can be called from destructor of another
2279 //global static object, fallback to rand()
2283 // On Windows srand() and rand() already use Thread-Local-Storage
2284 // to store the seed between calls
2285 // this is also valid for QT_NO_THREAD
2294 This macro is provided for convenience for writing infinite
2299 \snippet code/src_corelib_global_qglobal.cpp 31
2301 It is equivalent to \c{for (;;)}.
2303 If you're worried about namespace pollution, you can disable this
2304 macro by adding the following line to your \c .pro file:
2306 \snippet code/src_corelib_global_qglobal.cpp 32
2315 Same as \l{forever}.
2317 This macro is available even when \c no_keywords is specified
2318 using the \c .pro file's \c CONFIG variable.
2324 \macro foreach(variable, container)
2327 This macro is used to implement Qt's \c foreach loop. The \a
2328 variable parameter is a variable name or variable definition; the
2329 \a container parameter is a Qt container whose value type
2330 corresponds to the type of the variable. See \l{The foreach
2331 Keyword} for details.
2333 If you're worried about namespace pollution, you can disable this
2334 macro by adding the following line to your \c .pro file:
2336 \snippet code/src_corelib_global_qglobal.cpp 33
2342 \macro Q_FOREACH(variable, container)
2345 Same as foreach(\a variable, \a container).
2347 This macro is available even when \c no_keywords is specified
2348 using the \c .pro file's \c CONFIG variable.
2354 \macro QT_TR_NOOP(sourceText)
2357 Marks the string literal \a sourceText for dynamic translation in
2358 the current context (class), i.e the stored \a sourceText will not
2361 The macro expands to \a sourceText.
2365 \snippet code/src_corelib_global_qglobal.cpp 34
2367 The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
2368 that the source string is encoded in UTF-8. Corresponding variants
2369 exist in the QT_TRANSLATE_NOOP() family of macros, too.
2371 \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2375 \macro QT_TRANSLATE_NOOP(context, sourceText)
2378 Marks the string literal \a sourceText for dynamic translation in
2379 the given \a context; i.e, the stored \a sourceText will not be
2380 altered. The \a context is typically a class and also needs to
2381 be specified as string literal.
2383 The macro expands to \a sourceText.
2387 \snippet code/src_corelib_global_qglobal.cpp 35
2389 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
2393 \macro QT_TRANSLATE_NOOP3(context, sourceText, comment)
2397 Marks the string literal \a sourceText for dynamic translation in the
2398 given \a context and with \a comment, i.e the stored \a sourceText will
2399 not be altered. The \a context is typically a class and also needs to
2400 be specified as string literal. The string literal \a comment
2401 will be available for translators using e.g. Qt Linguist.
2403 The macro expands to anonymous struct of the two string
2404 literals passed as \a sourceText and \a comment.
2408 \snippet code/src_corelib_global_qglobal.cpp 36
2410 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2414 \fn QString qtTrId(const char *id, int n = -1)
2419 \brief The qtTrId function finds and returns a translated string.
2421 Returns a translated string identified by \a id.
2422 If no matching string is found, the id itself is returned. This
2423 should not happen under normal conditions.
2425 If \a n >= 0, all occurrences of \c %n in the resulting string
2426 are replaced with a decimal representation of \a n. In addition,
2427 depending on \a n's value, the translation text may vary.
2429 Meta data and comments can be passed as documented for QObject::tr().
2430 In addition, it is possible to supply a source string template like that:
2436 \tt{\\begincomment% <C string> \\endcomment}
2440 \snippet code/src_corelib_global_qglobal.cpp qttrid
2442 Creating QM files suitable for use with this function requires passing
2443 the \c -idbased option to the \c lrelease tool.
2445 \warning This method is reentrant only if all translators are
2446 installed \e before calling this method. Installing or removing
2447 translators while performing translations is not supported. Doing
2448 so will probably result in crashes or other undesirable behavior.
2450 \sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
2454 \macro QT_TRID_NOOP(id)
2458 \brief The QT_TRID_NOOP macro marks an id for dynamic translation.
2460 The only purpose of this macro is to provide an anchor for attaching
2461 meta data like to qtTrId().
2463 The macro expands to \a id.
2467 \snippet code/src_corelib_global_qglobal.cpp qttrid_noop
2469 \sa qtTrId(), {Internationalization with Qt}
2473 \macro Q_LIKELY(expr)
2477 \brief Hints to the compiler that the enclosed condition, \a expr, is
2478 likely to evaluate to \c true.
2480 Use of this macro can help the compiler to optimize the code.
2484 \snippet code/src_corelib_global_qglobal.cpp qlikely
2490 \macro Q_UNLIKELY(expr)
2494 \brief Hints to the compiler that the enclosed condition, \a expr, is
2495 likely to evaluate to \c false.
2497 Use of this macro can help the compiler to optimize the code.
2501 \snippet code/src_corelib_global_qglobal.cpp qunlikely
2507 \macro QT_POINTER_SIZE
2510 Expands to the size of a pointer in bytes (4 or 8). This is
2511 equivalent to \c sizeof(void *) but can be used in a preprocessor
2520 Use qAbs(\a n) instead.
2530 Use qMin(\a x, \a y) instead.
2540 Use qMax(\a x, \a y) instead.
2546 \macro const char *qPrintable(const QString &str)
2549 Returns \a str as a \c{const char *}. This is equivalent to
2550 \a{str}.toLocal8Bit().constData().
2552 The char pointer will be invalid after the statement in which
2553 qPrintable() is used. This is because the array returned by
2554 toLocal8Bit() will fall out of scope.
2558 \snippet code/src_corelib_global_qglobal.cpp 37
2561 \sa qDebug(), qWarning(), qCritical(), qFatal()
2565 \macro Q_DECLARE_TYPEINFO(Type, Flags)
2568 You can use this macro to specify information about a custom type
2569 \a Type. With accurate type information, Qt's \l{Container Classes}
2570 {generic containers} can choose appropriate storage methods and
2573 \a Flags can be one of the following:
2576 \li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
2577 data) type with no constructor or destructor, or else a type where
2578 every bit pattern is a valid object and memcpy() creates a valid
2579 independent copy of the object.
2580 \li \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
2581 and/or a destructor but can be moved in memory using \c
2583 \li \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
2584 constructors and/or a destructor and that it may not be moved
2588 Example of a "primitive" type:
2590 \snippet code/src_corelib_global_qglobal.cpp 38
2592 An example of a non-POD "primitive" type is QUuid: Even though
2593 QUuid has constructors (and therefore isn't POD), every bit
2594 pattern still represents a valid object, and memcpy() can be used
2595 to create a valid independent copy of a QUuid object.
2597 Example of a movable type:
2599 \snippet code/src_corelib_global_qglobal.cpp 39
2603 \macro Q_UNUSED(name)
2606 Indicates to the compiler that the parameter with the specified
2607 \a name is not used in the body of a function. This can be used to
2608 suppress compiler warnings while allowing functions to be defined
2609 with meaningful parameter names in their signatures.
2612 struct QInternal_CallBackTable {
2613 QVector<QList<qInternalCallback> > callbacks;
2616 Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
2618 bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
2620 if (cb >= 0 && cb < QInternal::LastCallback) {
2621 QInternal_CallBackTable *cbt = global_callback_table();
2622 cbt->callbacks.resize(cb + 1);
2623 cbt->callbacks[cb].append(callback);
2629 bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
2631 if (cb >= 0 && cb < QInternal::LastCallback) {
2632 QInternal_CallBackTable *cbt = global_callback_table();
2633 return (bool) cbt->callbacks[cb].removeAll(callback);
2638 bool QInternal::activateCallbacks(Callback cb, void **parameters)
2640 Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
2642 QInternal_CallBackTable *cbt = global_callback_table();
2643 if (cbt && cb < cbt->callbacks.size()) {
2644 QList<qInternalCallback> callbacks = cbt->callbacks[cb];
2646 for (int i=0; i<callbacks.size(); ++i)
2647 ret |= (callbacks.at(i))(parameters);
2657 This macro can be used to determine the byte order your system
2658 uses for storing data in memory. i.e., whether your system is
2659 little-endian or big-endian. It is set by Qt to one of the macros
2660 Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
2661 about endian-ness, but you might, for example if you need to know
2662 which byte of an integer or UTF-16 character is stored in the
2663 lowest address. Endian-ness is important in networking, where
2664 computers with different values for Q_BYTE_ORDER must pass data
2667 Use this macro as in the following examples.
2669 \snippet code/src_corelib_global_qglobal.cpp 40
2671 \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
2675 \macro Q_LITTLE_ENDIAN
2678 This macro represents a value you can compare to the macro
2679 Q_BYTE_ORDER to determine the endian-ness of your system. In a
2680 little-endian system, the least significant byte is stored at the
2681 lowest address. The other bytes follow in increasing order of
2684 \snippet code/src_corelib_global_qglobal.cpp 41
2686 \sa Q_BYTE_ORDER, Q_BIG_ENDIAN
2693 This macro represents a value you can compare to the macro
2694 Q_BYTE_ORDER to determine the endian-ness of your system. In a
2695 big-endian system, the most significant byte is stored at the
2696 lowest address. The other bytes follow in decreasing order of
2699 \snippet code/src_corelib_global_qglobal.cpp 42
2701 \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
2705 \macro Q_GLOBAL_STATIC(type, name)
2708 Declares a global static variable with the given \a type and \a name.
2710 Use this macro to instantiate an object in a thread-safe way, creating
2711 a global pointer that can be used to refer to it.
2713 \warning This macro is subject to a race condition that can cause the object
2714 to be constructed twice. However, if this occurs, the second instance will
2715 be immediately deleted.
2718 \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2719 by Scott Meyers and Andrei Alexandrescu.
2723 \macro Q_GLOBAL_STATIC_WITH_ARGS(type, name, arguments)
2726 Declares a global static variable with the specified \a type and \a name.
2728 Use this macro to instantiate an object using the \a arguments specified
2729 in a thread-safe way, creating a global pointer that can be used to refer
2732 \warning This macro is subject to a race condition that can cause the object
2733 to be constructed twice. However, if this occurs, the second instance will
2734 be immediately deleted.
2737 \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2738 by Scott Meyers and Andrei Alexandrescu.
2745 If this macro is defined to \c ns all Qt classes are put in a namespace
2746 called \c ns. Also, moc will output code putting metaobjects etc.
2747 into namespace \c ns.
2749 \sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
2750 QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
2751 QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
2752 QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
2756 \macro QT_PREPEND_NAMESPACE(identifier)
2759 This macro qualifies \a identifier with the full namespace.
2760 It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
2761 and only \a identifier otherwise.
2767 \macro QT_USE_NAMESPACE
2770 This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
2771 and nothing otherwise.
2777 \macro QT_BEGIN_NAMESPACE
2780 This macro expands to
2782 \snippet code/src_corelib_global_qglobal.cpp begin namespace macro
2784 if \c QT_NAMESPACE is defined and nothing otherwise. If should always
2785 appear in the file-level scope and be followed by \c QT_END_NAMESPACE
2786 at the same logical level with respect to preprocessor conditionals
2789 As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
2790 and Qt source files after the last \c{#include} line and before the first
2791 declaration. In Qt headers using \c QT_BEGIN_HEADER, \c QT_BEGIN_NAMESPACE
2792 follows \c QT_BEGIN_HEADER immediately.
2794 If that rule can't be followed because, e.g., \c{#include} lines and
2795 declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
2796 the first declaration and wrap the \c{#include} lines in
2797 \c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
2799 When using the \c QT_NAMESPACE feature in user code
2800 (e.g., when building plugins statically linked to Qt) where
2801 the user code is not intended to go into the \c QT_NAMESPACE
2802 namespace, all forward declarations of Qt classes need to
2803 be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
2804 After that, a \c QT_USE_NAMESPACE should follow.
2805 No further changes should be needed.
2811 \macro QT_END_NAMESPACE
2814 This macro expands to
2816 \snippet code/src_corelib_global_qglobal.cpp end namespace macro
2818 if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
2819 the effect of \c QT_BEGIN_NAMESPACE.
2821 If a source file ends with a \c{#include} directive that includes a moc file,
2822 \c QT_END_NAMESPACE should be placed before that \c{#include}.
2828 \macro QT_BEGIN_INCLUDE_NAMESPACE
2831 This macro is equivalent to \c QT_END_NAMESPACE.
2832 It only serves as syntactic sugar and is intended
2833 to be used before #include lines within a
2834 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2840 \macro QT_END_INCLUDE_NAMESPACE
2843 This macro is equivalent to \c QT_BEGIN_NAMESPACE.
2844 It only serves as syntactic sugar and is intended
2845 to be used after #include lines within a
2846 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2852 \macro QT_BEGIN_MOC_NAMESPACE
2855 This macro is output by moc at the beginning of
2856 moc files. It is equivalent to \c QT_USE_NAMESPACE.
2862 \macro QT_END_MOC_NAMESPACE
2865 This macro is output by moc at the beginning of
2866 moc files. It expands to nothing.
2872 \fn bool qFuzzyCompare(double p1, double p2)
2877 Compares the floating point value \a p1 and \a p2 and
2878 returns \c true if they are considered equal, otherwise \c false.
2880 Note that comparing values where either \a p1 or \a p2 is 0.0 will not work.
2881 The solution to this is to compare against values greater than or equal to 1.0.
2883 \snippet code/src_corelib_global_qglobal.cpp 46
2885 The two numbers are compared in a relative way, where the
2886 exactness is stronger the smaller the numbers are.
2890 \fn bool qFuzzyCompare(float p1, float p2)
2895 Compares the floating point value \a p1 and \a p2 and
2896 returns \c true if they are considered equal, otherwise \c false.
2898 The two numbers are compared in a relative way, where the
2899 exactness is stronger the smaller the numbers are.
2903 \macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
2906 This macro can be used to ensure that the application is run
2907 against a recent enough version of Qt. This is especially useful
2908 if your application depends on a specific bug fix introduced in a
2909 bug-fix release (e.g., 4.0.2).
2911 The \a argc and \a argv parameters are the \c main() function's
2912 \c argc and \c argv parameters. The \a version parameter is a
2913 string literal that specifies which version of Qt the application
2914 requires (e.g., "4.0.2").
2918 \snippet code/src_gui_dialogs_qmessagebox.cpp 4
2922 \macro Q_DECL_EXPORT
2925 This macro marks a symbol for shared library export (see
2926 \l{sharedlibrary.html}{Creating Shared Libraries}).
2932 \macro Q_DECL_IMPORT
2935 This macro declares a symbol to be an import from a shared library (see
2936 \l{sharedlibrary.html}{Creating Shared Libraries}).
2942 \macro Q_DECL_CONSTEXPR
2945 This macro can be used to declare variable that should be constructed at compile-time,
2946 or an inline function that can be computed at compile-time.
2948 It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
2953 \macro qDebug(const char *message, ...)
2956 Calls the message handler with the debug message \a message. If no
2957 message handler has been installed, the message is printed to
2958 stderr. Under Windows, the message is sent to the console, if it is a
2959 console application; otherwise, it is sent to the debugger. On Blackberry the
2960 message is sent to slogger2. This function does nothing if \c QT_NO_DEBUG_OUTPUT
2961 was defined during compilation.
2963 If you pass the function a format string and a list of arguments,
2964 it works in similar way to the C printf() function. The format
2965 should be a Latin-1 string.
2969 \snippet code/src_corelib_global_qglobal.cpp 24
2971 If you include \c <QtDebug>, a more convenient syntax is also
2974 \snippet code/src_corelib_global_qglobal.cpp 25
2976 With this syntax, the function returns a QDebug object that is
2977 configured to use the QtDebugMsg message type. It automatically
2978 puts a single space between each item, and outputs a newline at
2979 the end. It supports many C++ and Qt types.
2981 To suppress the output at run-time, install your own message handler
2982 with qInstallMessageHandler().
2984 \sa qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
2985 {Debugging Techniques}
2989 \macro qWarning(const char *message, ...)
2992 Calls the message handler with the warning message \a message. If no
2993 message handler has been installed, the message is printed to
2994 stderr. Under Windows, the message is sent to the debugger.
2995 On Blackberry the message is sent to slogger2. This
2996 function does nothing if \c QT_NO_WARNING_OUTPUT was defined
2997 during compilation; it exits if the environment variable \c
2998 QT_FATAL_WARNINGS is defined.
3000 This function takes a format string and a list of arguments,
3001 similar to the C printf() function. The format should be a Latin-1
3005 \snippet code/src_corelib_global_qglobal.cpp 26
3007 If you include <QtDebug>, a more convenient syntax is
3010 \snippet code/src_corelib_global_qglobal.cpp 27
3012 This syntax inserts a space between each item, and
3013 appends a newline at the end.
3015 To suppress the output at runtime, install your own message handler
3016 with qInstallMessageHandler().
3018 \sa qDebug(), qCritical(), qFatal(), qInstallMessageHandler(),
3019 {Debugging Techniques}
3023 \macro qCritical(const char *message, ...)
3026 Calls the message handler with the critical message \a message. If no
3027 message handler has been installed, the message is printed to
3028 stderr. Under Windows, the message is sent to the debugger.
3029 On Blackberry the message is sent to slogger2.
3031 This function takes a format string and a list of arguments,
3032 similar to the C printf() function. The format should be a Latin-1
3036 \snippet code/src_corelib_global_qglobal.cpp 28
3038 If you include <QtDebug>, a more convenient syntax is
3041 \snippet code/src_corelib_global_qglobal.cpp 29
3043 A space is inserted between the items, and a newline is
3044 appended at the end.
3046 To suppress the output at runtime, install your own message handler
3047 with qInstallMessageHandler().
3049 \sa qDebug(), qWarning(), qFatal(), qInstallMessageHandler(),
3050 {Debugging Techniques}
3054 \macro qFatal(const char *message, ...)
3057 Calls the message handler with the fatal message \a message. If no
3058 message handler has been installed, the message is printed to
3059 stderr. Under Windows, the message is sent to the debugger.
3060 On Blackberry the message is sent to slogger2.
3062 If you are using the \b{default message handler} this function will
3063 abort on Unix systems to create a core dump. On Windows, for debug builds,
3064 this function will report a _CRT_ERROR enabling you to connect a debugger
3067 This function takes a format string and a list of arguments,
3068 similar to the C printf() function.
3071 \snippet code/src_corelib_global_qglobal.cpp 30
3073 To suppress the output at runtime, install your own message handler
3074 with qInstallMessageHandler().
3076 \sa qDebug(), qCritical(), qWarning(), qInstallMessageHandler(),
3077 {Debugging Techniques}
3084 It expands to "std::move" if your compiler supports that C++11 function, or to nothing
3089 \macro Q_DECL_NOTHROW
3093 This macro marks a function as never throwing, under no
3094 circumstances. If the function does nevertheless throw, the
3095 behaviour is undefined.
3097 The macro expands to either "throw()", if that has some benefit on
3098 the compiler, or to C++11 noexcept, if available, or to nothing
3101 If you need C++11 noexcept semantics, don't use this macro, use
3102 Q_DECL_NOEXCEPT/Q_DECL_NOEXCEPT_EXPR instead.
3104 \sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR
3108 \macro QT_TERMINATE_ON_EXCEPTION(expr)
3112 In general, use of the Q_DECL_NOEXCEPT macro is preferred over
3113 Q_DECL_NOTHROW, because it exhibits well-defined behavior and
3114 supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However,
3115 use of Q_DECL_NOTHROW has the advantage that Windows builds
3116 benefit on a wide range or compiler versions that do not yet
3117 support the C++11 noexcept feature.
3119 It may therefore be beneficial to use Q_DECL_NOTHROW and emulate
3120 the C++11 behavior manually with an embedded try/catch.
3122 Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this
3123 purpose. It either expands to \c expr (if Qt is compiled without
3124 exception support or the compiler supports C++11 noexcept
3127 try { expr; } catch(...) { qTerminate(); }
3131 Since this macro expands to just \c expr if the compiler supports
3132 C++11 noexcept, expecting the compiler to take over responsibility
3133 of calling std::terminate() in that case, it should not be used
3134 outside Q_DECL_NOTHROW functions.
3136 \sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate()
3140 \macro Q_DECL_NOEXCEPT
3144 This macro marks a function as never throwing. If the function
3145 does nevertheless throw, the behaviour is defined:
3146 std::terminate() is called.
3148 The macro expands to C++11 noexcept, if available, or to nothing
3151 If you need the operator version of C++11 noexcept, use
3152 Q_DECL_NOEXCEPT_EXPR(x).
3154 If you don't need C++11 noexcept semantics, e.g. because your
3155 function can't possibly throw, don't use this macro, use
3156 Q_DECL_NOTHROW instead.
3158 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR
3162 \macro Q_DECL_NOEXCEPT_EXPR(x)
3166 This macro marks a function as non-throwing if \a x is true. If
3167 the function does nevertheless throw, the behaviour is defined:
3168 std::terminate() is called.
3170 The macro expands to C++11 noexcept(x), if available, or to
3173 If you need the always-true version of C++11 noexcept, use
3176 If you don't need C++11 noexcept semantics, e.g. because your
3177 function can't possibly throw, don't use this macro, use
3178 Q_DECL_NOTHROW instead.
3180 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR
3184 \macro Q_DECL_OVERRIDE
3188 This macro can be used to declare an overriding virtual
3189 function. Use of this markup will allow the compiler to generate
3190 an error if the overriding virtual function does not in fact
3193 It expands to "override" if your compiler supports that C++11
3194 contextual keyword, or to nothing otherwise.
3196 The macro goes at the end of the function, usually after the
3199 // generate error if this doesn't actually override anything:
3200 virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
3211 This macro can be used to declare an overriding virtual or a class
3212 as "final", with Java semantics. Further-derived classes can then
3213 no longer override this virtual function, or inherit from this
3214 class, respectively.
3216 It expands to "final" if your compiler supports that C++11
3217 contextual keyword, or something non-standard if your compiler
3218 supports something close enough to the C++11 semantics, or to
3221 The macro goes at the end of the function, usually after the
3224 // more-derived classes no longer permitted to override this:
3225 virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_FINAL;
3228 For classes, it goes in front of the \c{:} in the class
3231 class QRect Q_DECL_FINAL { // cannot be derived from