1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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_MACX) && !defined(QT_NO_CORESERVICES)
76 #include <CoreServices/CoreServices.h>
84 \brief The QFlag class is a helper data type for QFlags.
86 It is equivalent to a plain \c int, except with respect to
87 function overloading and type conversions. You should never need
88 to use this class in your applications.
94 \fn QFlag::QFlag(int value)
96 Constructs a QFlag object that stores the given \a value.
100 \fn QFlag::operator int() const
102 Returns the value stored by the QFlag object.
107 \brief The QFlags class provides a type-safe way of storing
108 OR-combinations of enum values.
113 The QFlags<Enum> class is a template class, where Enum is an enum
114 type. QFlags is used throughout Qt for storing combinations of
117 The traditional C++ approach for storing OR-combinations of enum
118 values is to use an \c int or \c uint variable. The inconvenience
119 with this approach is that there's no type checking at all; any
120 enum value can be OR'd with any other enum value and passed on to
121 a function that takes an \c int or \c uint.
123 Qt uses QFlags to provide type safety. For example, the
124 Qt::Alignment type is simply a typedef for
125 QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
126 Qt::Alignment parameter, which means that any combination of
127 Qt::AlignmentFlag values,or 0, is legal:
129 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 0
131 If you try to pass a value from another enum or just a plain
132 integer other than 0, the compiler will report an error. If you
133 need to cast integer values to flags in a untyped fashion, you can
134 use the explicit QFlags constructor as cast operator.
136 If you want to use QFlags for your own enum types, use
137 the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
141 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 1
143 You can then use the \c MyClass::Options type to store
144 combinations of \c MyClass::Option values.
146 \section1 Flags and the Meta-Object System
148 The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
149 system, so they cannot be used by Qt Script or edited in Qt Designer.
150 To make the flags available for these purposes, the Q_FLAGS() macro must
153 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp meta-object flags
155 \section1 Naming Convention
157 A sensible naming convention for enum types and associated QFlags
158 types is to give a singular name to the enum type (e.g., \c
159 Option) and a plural name to the QFlags type (e.g., \c Options).
160 When a singular name is desired for the QFlags type (e.g., \c
161 Alignment), you can use \c Flag as the suffix for the enum type
162 (e.g., \c AlignmentFlag).
168 \typedef QFlags::enum_type
170 Typedef for the Enum template type.
174 \fn QFlags::QFlags(const QFlags &other)
176 Constructs a copy of \a other.
180 \fn QFlags::QFlags(Enum flag)
182 Constructs a QFlags object storing the given \a flag.
186 \fn QFlags::QFlags(Zero zero)
188 Constructs a QFlags object with no flags set. \a zero must be a
193 \fn QFlags::QFlags(QFlag value)
195 Constructs a QFlags object initialized with the given integer \a
198 The QFlag type is a helper type. By using it here instead of \c
199 int, we effectively ensure that arbitrary enum values cannot be
200 cast to a QFlags, whereas untyped enum values (i.e., \c int
205 \fn QFlags &QFlags::operator=(const QFlags &other)
207 Assigns \a other to this object and returns a reference to this
212 \fn QFlags &QFlags::operator&=(int mask)
214 Performs a bitwise AND operation with \a mask and stores the
215 result in this QFlags object. Returns a reference to this object.
217 \sa operator&(), operator|=(), operator^=()
221 \fn QFlags &QFlags::operator&=(uint mask)
227 \fn QFlags &QFlags::operator|=(QFlags other)
229 Performs a bitwise OR operation with \a other and stores the
230 result in this QFlags object. Returns a reference to this object.
232 \sa operator|(), operator&=(), operator^=()
236 \fn QFlags &QFlags::operator|=(Enum other)
242 \fn QFlags &QFlags::operator^=(QFlags other)
244 Performs a bitwise XOR operation with \a other and stores the
245 result in this QFlags object. Returns a reference to this object.
247 \sa operator^(), operator&=(), operator|=()
251 \fn QFlags &QFlags::operator^=(Enum other)
257 \fn QFlags::operator int() const
259 Returns the value stored in the QFlags object as an integer.
263 \fn QFlags QFlags::operator|(QFlags other) const
265 Returns a QFlags object containing the result of the bitwise OR
266 operation on this object and \a other.
268 \sa operator|=(), operator^(), operator&(), operator~()
272 \fn QFlags QFlags::operator|(Enum other) const
278 \fn QFlags QFlags::operator^(QFlags other) const
280 Returns a QFlags object containing the result of the bitwise XOR
281 operation on this object and \a other.
283 \sa operator^=(), operator&(), operator|(), operator~()
287 \fn QFlags QFlags::operator^(Enum other) const
293 \fn QFlags QFlags::operator&(int mask) const
295 Returns a QFlags object containing the result of the bitwise AND
296 operation on this object and \a mask.
298 \sa operator&=(), operator|(), operator^(), operator~()
302 \fn QFlags QFlags::operator&(uint mask) const
308 \fn QFlags QFlags::operator&(Enum mask) const
314 \fn QFlags QFlags::operator~() const
316 Returns a QFlags object that contains the bitwise negation of
319 \sa operator&(), operator|(), operator^()
323 \fn bool QFlags::operator!() const
325 Returns true if no flag is set (i.e., if the value stored by the
326 QFlags object is 0); otherwise returns false.
330 \fn bool QFlags::testFlag(Enum flag) const
333 Returns true if the \a flag is set, otherwise false.
337 \macro Q_DISABLE_COPY(Class)
340 Disables the use of copy constructors and assignment operators
341 for the given \a Class.
343 Instances of subclasses of QObject should not be thought of as
344 values that can be copied or assigned, but as unique identities.
345 This means that when you create your own subclass of QObject
346 (director or indirect), you should \e not give it a copy constructor
347 or an assignment operator. However, it may not enough to simply
348 omit them from your class, because, if you mistakenly write some code
349 that requires a copy constructor or an assignment operator (it's easy
350 to do), your compiler will thoughtfully create it for you. You must
353 The curious user will have seen that the Qt classes derived
354 from QObject typically include this macro in a private section:
356 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 43
358 It declares a copy constructor and an assignment operator in the
359 private section, so that if you use them by mistake, the compiler
360 will report an error.
362 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 44
364 But even this might not catch absolutely every case. You might be
365 tempted to do something like this:
367 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 45
369 First of all, don't do that. Most compilers will generate code that
370 uses the copy constructor, so the privacy violation error will be
371 reported, but your C++ compiler is not required to generate code for
372 this statement in a specific way. It could generate code using
373 \e{neither} the copy constructor \e{nor} the assignment operator we
374 made private. In that case, no error would be reported, but your
375 application would probably crash when you called a member function
380 \macro Q_DECLARE_FLAGS(Flags, Enum)
383 The Q_DECLARE_FLAGS() macro expands to
385 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 2
387 \a Enum is the name of an existing enum type, whereas \a Flags is
388 the name of the QFlags<\e{Enum}> typedef.
390 See the QFlags documentation for details.
392 \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
396 \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
399 The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
400 operator|() functions for \a Flags, which is of type QFlags<T>.
402 See the QFlags documentation for details.
404 \sa Q_DECLARE_FLAGS()
408 \headerfile <QtGlobal>
409 \title Global Qt Declarations
412 \brief The <QtGlobal> header file includes the fundamental global
413 declarations. It is included by most other Qt header files.
415 The global declarations include \l{types}, \l{functions} and
418 The type definitions are partly convenience definitions for basic
419 types (some of which guarantee certain bit-sizes on all platforms
420 supported by Qt), partly types related to Qt message handling. The
421 functions are related to generating messages, Qt version handling
422 and comparing and adjusting object values. And finally, some of
423 the declared macros enable programmers to add compiler or platform
424 specific code to their applications, while others are convenience
425 macros for larger operations.
429 The header file declares several type definitions that guarantee a
430 specified bit-size on all platforms supported by Qt for various
431 basic types, for example \l qint8 which is a signed char
432 guaranteed to be 8-bit on all platforms supported by Qt. The
433 header file also declares the \l qlonglong type definition for \c
434 {long long int } (\c __int64 on Windows).
436 Several convenience type definitions are declared: \l qreal for \c
437 double, \l uchar for \c unsigned char, \l uint for \c unsigned
438 int, \l ulong for \c unsigned long and \l ushort for \c unsigned
441 Finally, the QtMsgType definition identifies the various messages
442 that can be generated and sent to a Qt message handler;
443 QMessageHandler is a type definition for a pointer to a function with
445 \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}.
446 QMessageLogContext class contains the line, file, and function the
447 message was logged at. This information is created by the QMessageLogger
452 The <QtGlobal> header file contains several functions comparing
453 and adjusting an object's value. These functions take a template
454 type as argument: You can retrieve the absolute value of an object
455 using the qAbs() function, and you can bound a given object's
456 value by given minimum and maximum values using the qBound()
457 function. You can retrieve the minimum and maximum of two given
458 objects using qMin() and qMax() respectively. All these functions
459 return a corresponding template type; the template types can be
460 replaced by any other type.
464 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 3
466 <QtGlobal> also contains functions that generate messages from the
467 given string argument: qCritical(), qDebug(), qFatal() and
468 qWarning(). These functions call the message handler with the
473 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 4
475 The remaining functions are qRound() and qRound64(), which both
476 accept a \l qreal value as their argument returning the value
477 rounded up to the nearest integer and 64-bit integer respectively,
478 the qInstallMessageHandler() function which installs the given
479 QMessageHandler, and the qVersion() function which returns the
480 version number of Qt at run-time as a string.
484 The <QtGlobal> header file provides a range of macros (Q_CC_*)
485 that are defined if the application is compiled using the
486 specified platforms. For example, the Q_CC_SUN macro is defined if
487 the application is compiled using Forte Developer, or Sun Studio
488 C++. The header file also declares a range of macros (Q_OS_*)
489 that are defined for the specified platforms. For example,
490 Q_OS_X11 which is defined for the X Window System.
492 The purpose of these macros is to enable programmers to add
493 compiler or platform specific code to their application.
495 The remaining macros are convenience macros for larger operations:
496 The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the
497 possibility of marking text for dynamic translation,
498 i.e. translation without changing the stored source text. The
499 Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
500 level of refinement. The Q_FOREACH() and foreach() macros
501 implement Qt's foreach loop.
503 The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
504 64-bit integer literals in a platform-independent way. The
505 Q_CHECK_PTR() macro prints a warning containing the source code's
506 file name and line number, saying that the program ran out of
507 memory, if the pointer is 0. The qPrintable() macro represent an
508 easy way of printing text.
510 Finally, the QT_POINTER_SIZE macro expands to the size of a
511 pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
512 expand to a numeric value or a string, respectively, specifying
513 Qt's version number, i.e the version the application is compiled
516 \sa <QtAlgorithms>, QSysInfo
523 Typedef for \c double on all platforms except for those using CPUs with
525 On ARM-based platforms, \c qreal is a typedef for \c float for performance
532 Convenience typedef for \c{unsigned char}.
536 \fn qt_set_sequence_auto_mnemonic(bool on)
539 Enables automatic mnemonics on Mac if \a on is true; otherwise
540 this feature is disabled.
542 Note that this function is only available on Mac where mnemonics
543 are disabled by default.
545 To access to this function, use an extern declaration:
546 extern void qt_set_sequence_auto_mnemonic(bool b);
548 \sa {QShortcut#mnemonic}{QShortcut}
554 Convenience typedef for \c{unsigned short}.
560 Convenience typedef for \c{unsigned int}.
566 Convenience typedef for \c{unsigned long}.
572 Typedef for \c{signed char}. This type is guaranteed to be 8-bit
573 on all platforms supported by Qt.
580 Typedef for \c{unsigned char}. This type is guaranteed to
581 be 8-bit on all platforms supported by Qt.
587 Typedef for \c{signed short}. This type is guaranteed to be
588 16-bit on all platforms supported by Qt.
595 Typedef for \c{unsigned short}. This type is guaranteed to
596 be 16-bit on all platforms supported by Qt.
602 Typedef for \c{signed int}. This type is guaranteed to be 32-bit
603 on all platforms supported by Qt.
610 Typedef for \c{unsigned int}. This type is guaranteed to
611 be 32-bit on all platforms supported by Qt.
617 Typedef for \c{long long int} (\c __int64 on Windows). This type
618 is guaranteed to be 64-bit on all platforms supported by Qt.
620 Literals of this type can be created using the Q_INT64_C() macro:
622 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 5
624 \sa Q_INT64_C(), quint64, qlonglong
631 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
632 Windows). This type is guaranteed to be 64-bit on all platforms
635 Literals of this type can be created using the Q_UINT64_C()
638 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 6
640 \sa Q_UINT64_C(), qint64, qulonglong
647 Integral type for representing a pointers (useful for hashing,
650 Typedef for either quint32 or quint64. This type is guaranteed to
651 be the same size as a pointer on all platforms supported by Qt. On
652 a system with 32-bit pointers, quintptr is a typedef for quint32;
653 on a system with 64-bit pointers, quintptr is a typedef for
656 Note that quintptr is unsigned. Use qptrdiff for signed values.
658 \sa qptrdiff, quint32, quint64
665 Integral type for representing pointer differences.
667 Typedef for either qint32 or qint64. This type is guaranteed to be
668 the same size as a pointer on all platforms supported by Qt. On a
669 system with 32-bit pointers, quintptr is a typedef for quint32; on
670 a system with 64-bit pointers, quintptr is a typedef for quint64.
672 Note that qptrdiff is signed. Use quintptr for unsigned values.
674 \sa quintptr, qint32, qint64
681 This enum describes the messages that can be sent to a message
682 handler (QtMsgHandler). You can use the enum to identify and
683 associate the various message types with the appropriate
687 A message generated by the qDebug() function.
689 A message generated by the qWarning() function.
691 A message generated by the qCritical() function.
693 A message generated by the qFatal() function.
697 \sa QMessageHandler, qInstallMessageHandler()
700 /*! \typedef QFunctionPointer
703 This is a typedef for \c{void (*)()}, a pointer to a function that takes
704 no arguments and returns void.
707 /*! \macro qint64 Q_INT64_C(literal)
710 Wraps the signed 64-bit integer \a literal in a
711 platform-independent way.
715 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 8
717 \sa qint64, Q_UINT64_C()
720 /*! \macro quint64 Q_UINT64_C(literal)
723 Wraps the unsigned 64-bit integer \a literal in a
724 platform-independent way.
728 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 9
730 \sa quint64, Q_INT64_C()
733 /*! \typedef qlonglong
736 Typedef for \c{long long int} (\c __int64 on Windows). This is
737 the same as \l qint64.
739 \sa qulonglong, qint64
746 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
747 Windows). This is the same as \l quint64.
749 \sa quint64, qlonglong
752 /*! \fn const T &qAbs(const T &value)
755 Compares \a value to the 0 of type T and returns the absolute
756 value. Thus if T is \e {double}, then \a value is compared to
761 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 10
764 /*! \fn int qRound(qreal value)
767 Rounds \a value to the nearest integer.
771 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 11
774 /*! \fn qint64 qRound64(qreal value)
777 Rounds \a value to the nearest 64-bit integer.
781 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 12
784 /*! \fn const T &qMin(const T &value1, const T &value2)
787 Returns the minimum of \a value1 and \a value2.
791 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 13
796 /*! \fn const T &qMax(const T &value1, const T &value2)
799 Returns the maximum of \a value1 and \a value2.
803 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 14
808 /*! \fn const T &qBound(const T &min, const T &value, const T &max)
811 Returns \a value bounded by \a min and \a max. This is equivalent
812 to qMax(\a min, qMin(\a value, \a max)).
816 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 15
822 \fn int qMacVersion()
825 Use QSysInfo::MacintoshVersion instead.
831 \macro QT_VERSION_CHECK
834 Turns the major, minor and patch numbers of a version into an
835 integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
836 be compared with another similarly processed version id.
845 This macro expands a numeric value of the form 0xMMNNPP (MM =
846 major, NN = minor, PP = patch) that specifies Qt's version
847 number. For example, if you compile your application against Qt
848 4.1.2, the QT_VERSION macro will expand to 0x040102.
850 You can use QT_VERSION to use the latest Qt features where
855 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 16
857 \sa QT_VERSION_STR, qVersion()
861 \macro QT_VERSION_STR
864 This macro expands to a string that specifies Qt's version number
865 (for example, "4.1.2"). This is the version against which the
866 application is compiled.
868 \sa qVersion(), QT_VERSION
874 Returns the version number of Qt at run-time as a string (for
875 example, "4.1.2"). This may be a different version than the
876 version the application was compiled against.
881 const char *qVersion()
883 return QT_VERSION_STR;
895 /*****************************************************************************
896 System detection routines
897 *****************************************************************************/
901 \brief The QSysInfo class provides information about the system.
904 \o \l WordSize specifies the size of a pointer for the platform
905 on which the application is compiled.
906 \o \l ByteOrder specifies whether the platform is big-endian or
908 \o \l WindowsVersion specifies the version of the Windows operating
909 system on which the application is run (Windows only)
910 \o \l MacintoshVersion specifies the version of the Macintosh
911 operating system on which the application is run (Mac only).
914 Some constants are defined only on certain platforms. You can use
915 the preprocessor symbols Q_OS_WIN and Q_OS_MAC to test that
916 the application is compiled under Windows or Mac.
922 \enum QSysInfo::Sizes
924 This enum provides platform-specific information about the sizes of data
925 structures used by the underlying architecture.
927 \value WordSize The size in bits of a pointer for the platform on which
928 the application is compiled (32 or 64).
932 \variable QSysInfo::WindowsVersion
933 \brief the version of the Windows operating system on which the
934 application is run (Windows only)
938 \fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
941 Returns the version of the Windows operating system on which the
942 application is run (Windows only).
946 \variable QSysInfo::MacintoshVersion
947 \brief the version of the Macintosh operating system on which
948 the application is run (Mac only).
952 \enum QSysInfo::Endian
954 \value BigEndian Big-endian byte order (also called Network byte order)
955 \value LittleEndian Little-endian byte order
956 \value ByteOrder Equals BigEndian or LittleEndian, depending on
957 the platform's byte order.
961 \enum QSysInfo::WinVersion
963 This enum provides symbolic names for the various versions of the
964 Windows operating system. On Windows, the
965 QSysInfo::WindowsVersion variable gives the version of the system
966 on which the application is run.
968 MS-DOS-based versions:
970 \value WV_32s Windows 3.1 with Win 32s
971 \value WV_95 Windows 95
972 \value WV_98 Windows 98
973 \value WV_Me Windows Me
975 NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
977 \value WV_NT Windows NT (operating system version 4.0)
978 \value WV_2000 Windows 2000 (operating system version 5.0)
979 \value WV_XP Windows XP (operating system version 5.1)
980 \value WV_2003 Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
981 \value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
982 \value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
984 Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
986 \value WV_4_0 Operating system version 4.0, corresponds to Windows NT
987 \value WV_5_0 Operating system version 5.0, corresponds to Windows 2000
988 \value WV_5_1 Operating system version 5.1, corresponds to Windows XP
989 \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
990 \value WV_6_0 Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
991 \value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
995 \value WV_CE Windows CE
996 \value WV_CENET Windows CE .NET
997 \value WV_CE_5 Windows CE 5.x
998 \value WV_CE_6 Windows CE 6.x
1000 The following masks can be used for testing whether a Windows
1001 version is MS-DOS-based, NT-based, or CE-based:
1003 \value WV_DOS_based MS-DOS-based version of Windows
1004 \value WV_NT_based NT-based version of Windows
1005 \value WV_CE_based CE-based version of Windows
1011 \enum QSysInfo::MacVersion
1013 This enum provides symbolic names for the various versions of the
1014 Macintosh operating system. On Mac, the
1015 QSysInfo::MacintoshVersion variable gives the version of the
1016 system on which the application is run.
1018 \value MV_9 Mac OS 9 (unsupported)
1019 \value MV_10_0 Mac OS X 10.0 (unsupported)
1020 \value MV_10_1 Mac OS X 10.1 (unsupported)
1021 \value MV_10_2 Mac OS X 10.2 (unsupported)
1022 \value MV_10_3 Mac OS X 10.3
1023 \value MV_10_4 Mac OS X 10.4
1024 \value MV_10_5 Mac OS X 10.5
1025 \value MV_10_6 Mac OS X 10.6
1026 \value MV_10_7 Mac OS X 10.7
1027 \value MV_Unknown An unknown and currently unsupported platform
1029 \value MV_CHEETAH Apple codename for MV_10_0
1030 \value MV_PUMA Apple codename for MV_10_1
1031 \value MV_JAGUAR Apple codename for MV_10_2
1032 \value MV_PANTHER Apple codename for MV_10_3
1033 \value MV_TIGER Apple codename for MV_10_4
1034 \value MV_LEOPARD Apple codename for MV_10_5
1035 \value MV_SNOWLEOPARD Apple codename for MV_10_6
1036 \value MV_LION Apple codename for MV_10_7
1045 Defined on Darwin OS (synonym for Q_OS_MAC).
1052 Defined on all supported versions of Windows.
1059 Defined on Windows CE.
1073 Defined on Sun Solaris.
1087 Defined on DEC Ultrix.
1129 Defined on SGI Irix.
1136 Defined on HP Tru64 UNIX.
1143 Defined on SCO OpenServer 5.
1147 \macro Q_OS_UNIXWARE
1150 Defined on UnixWare 7, Open UNIX 8.
1164 Defined on GNU Hurd.
1178 Defined on Reliant UNIX.
1185 Defined on DYNIX/ptx.
1192 Defined on QNX Neutrino.
1206 Defined on Any BSD 4.4 system.
1213 Defined on Any UNIX BSD/SYSV system.
1220 Defined if the application is compiled using Digital Mars C/C++
1221 (used to be Symantec C++).
1228 Defined if the application is compiled using Microsoft Visual
1229 C/C++, Intel C++ for Windows.
1236 Defined if the application is compiled using Borland/Turbo C++.
1243 Defined if the application is compiled using Watcom C++.
1250 Defined if the application is compiled using GNU C++.
1257 Defined if the application is compiled using Comeau C++.
1264 Defined if the application is compiled using Edison Design Group
1272 Defined if the application is compiled using CenterLine C++.
1279 Defined if the application is compiled using Forte Developer, or
1287 Defined if the application is compiled using MIPSpro C++.
1294 Defined if the application is compiled using DEC C++.
1301 Defined if the application is compiled using HP aC++.
1308 Defined if the application is compiled using SCO OUDK and UDK.
1315 Defined if the application is compiled using Reliant C++.
1322 Defined if the application is compiled using KAI C++.
1329 Defined if the application is compiled using Intel C++ for Linux,
1330 Intel C++ for Windows.
1337 Defined if the application is compiled using MetaWare High C/C++.
1344 Defined if the application is compiled using Portland Group C++.
1351 Defined if the application is compiled using Green Hills
1352 Optimizing C++ Compilers.
1359 Defined on MAC OS (synonym for Darwin).
1363 \macro QT_DISABLE_DEPRECATED_BEFORE
1366 This macro can be defined in the project file to disable functions deprecated in
1367 a specified version of Qt or any earlier version. The default version number is 5.0,
1368 meaning that functions deprecated in or before Qt 5.0 will not be included.
1371 When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to
1372 disable functions deprecated in Qt 5.1 and earlier. In any release, set
1373 QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones
1374 deprecated in Qt 5.0
1377 #if defined(QT_BUILD_QMAKE)
1378 // needed to bootstrap qmake
1379 static const unsigned int qt_one = 1;
1380 const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
1383 #if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
1385 QT_BEGIN_INCLUDE_NAMESPACE
1386 #include "private/qcore_mac_p.h"
1387 #include "qnamespace.h"
1388 QT_END_INCLUDE_NAMESPACE
1390 Q_CORE_EXPORT OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
1392 return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
1395 Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1)
1399 CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
1402 Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
1403 return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
1405 #endif // defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
1407 #if defined(Q_OS_MAC)
1409 static QSysInfo::MacVersion macVersion()
1411 #ifndef QT_NO_CORESERVICES
1412 SInt32 gestalt_version;
1413 if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
1414 return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);
1417 return QSysInfo::MV_Unknown;
1419 const QSysInfo::MacVersion QSysInfo::MacintoshVersion = macVersion();
1421 #elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE)
1423 QT_BEGIN_INCLUDE_NAMESPACE
1424 #include "qt_windows.h"
1425 QT_END_INCLUDE_NAMESPACE
1427 QSysInfo::WinVersion QSysInfo::windowsVersion()
1429 #ifndef VER_PLATFORM_WIN32s
1430 #define VER_PLATFORM_WIN32s 0
1432 #ifndef VER_PLATFORM_WIN32_WINDOWS
1433 #define VER_PLATFORM_WIN32_WINDOWS 1
1435 #ifndef VER_PLATFORM_WIN32_NT
1436 #define VER_PLATFORM_WIN32_NT 2
1438 #ifndef VER_PLATFORM_WIN32_CE
1439 #define VER_PLATFORM_WIN32_CE 3
1442 static QSysInfo::WinVersion winver;
1445 winver = QSysInfo::WV_NT;
1446 OSVERSIONINFO osver;
1447 osver.dwOSVersionInfoSize = sizeof(osver);
1448 GetVersionEx(&osver);
1451 qt_cever = osver.dwMajorVersion * 100;
1452 qt_cever += osver.dwMinorVersion * 10;
1454 switch (osver.dwPlatformId) {
1455 case VER_PLATFORM_WIN32s:
1456 winver = QSysInfo::WV_32s;
1458 case VER_PLATFORM_WIN32_WINDOWS:
1459 // We treat Windows Me (minor 90) the same as Windows 98
1460 if (osver.dwMinorVersion == 90)
1461 winver = QSysInfo::WV_Me;
1462 else if (osver.dwMinorVersion == 10)
1463 winver = QSysInfo::WV_98;
1465 winver = QSysInfo::WV_95;
1468 case VER_PLATFORM_WIN32_CE:
1469 if (qt_cever >= 600)
1470 winver = QSysInfo::WV_CE_6;
1471 if (qt_cever >= 500)
1472 winver = QSysInfo::WV_CE_5;
1473 else if (qt_cever >= 400)
1474 winver = QSysInfo::WV_CENET;
1476 winver = QSysInfo::WV_CE;
1479 default: // VER_PLATFORM_WIN32_NT
1480 if (osver.dwMajorVersion < 5) {
1481 winver = QSysInfo::WV_NT;
1482 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) {
1483 winver = QSysInfo::WV_2000;
1484 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) {
1485 winver = QSysInfo::WV_XP;
1486 } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2) {
1487 winver = QSysInfo::WV_2003;
1488 } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0) {
1489 winver = QSysInfo::WV_VISTA;
1490 } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1) {
1491 winver = QSysInfo::WV_WINDOWS7;
1493 qWarning("Qt: Untested Windows version %d.%d detected!",
1494 int(osver.dwMajorVersion), int(osver.dwMinorVersion));
1495 winver = QSysInfo::WV_NT_based;
1501 QByteArray override = qgetenv("QT_WINVER_OVERRIDE");
1502 if (override.isEmpty())
1505 if (override == "Me")
1506 winver = QSysInfo::WV_Me;
1507 if (override == "95")
1508 winver = QSysInfo::WV_95;
1509 else if (override == "98")
1510 winver = QSysInfo::WV_98;
1511 else if (override == "NT")
1512 winver = QSysInfo::WV_NT;
1513 else if (override == "2000")
1514 winver = QSysInfo::WV_2000;
1515 else if (override == "2003")
1516 winver = QSysInfo::WV_2003;
1517 else if (override == "XP")
1518 winver = QSysInfo::WV_XP;
1519 else if (override == "VISTA")
1520 winver = QSysInfo::WV_VISTA;
1521 else if (override == "WINDOWS7")
1522 winver = QSysInfo::WV_WINDOWS7;
1529 const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
1534 \macro void Q_ASSERT(bool test)
1537 Prints a warning message containing the source code file name and
1538 line number if \a test is false.
1540 Q_ASSERT() is useful for testing pre- and post-conditions
1541 during development. It does nothing if \c QT_NO_DEBUG was defined
1546 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 17
1548 If \c b is zero, the Q_ASSERT statement will output the following
1549 message using the qFatal() function:
1551 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 18
1553 \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
1557 \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
1560 Prints the message \a what together with the location \a where,
1561 the source file name and line number if \a test is false.
1563 Q_ASSERT_X is useful for testing pre- and post-conditions during
1564 development. It does nothing if \c QT_NO_DEBUG was defined during
1569 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 19
1571 If \c b is zero, the Q_ASSERT_X statement will output the following
1572 message using the qFatal() function:
1574 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 20
1576 \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
1580 \macro void Q_CHECK_PTR(void *pointer)
1583 If \a pointer is 0, prints a warning message containing the source
1584 code's file name and line number, saying that the program ran out
1587 Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during
1592 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 21
1594 \sa qWarning(), {Debugging Techniques}
1598 \fn T *q_check_ptr(T *pointer)
1601 Users Q_CHECK_PTR on \a pointer, then returns \a pointer.
1603 This can be used as an inline version of Q_CHECK_PTR.
1607 \macro const char* Q_FUNC_INFO()
1610 Expands to a string that describe the function the macro resides in. How this string looks
1611 more specifically is compiler dependent. With GNU GCC it is typically the function signature,
1612 while with other compilers it might be the line and column number.
1614 Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
1616 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 22
1618 when instantiated with the integer type, will with the GCC compiler produce:
1620 \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
1622 If this macro is used outside a function, the behavior is undefined.
1626 The Q_CHECK_PTR macro calls this function if an allocation check
1629 void qt_check_pointer(const char *n, int l)
1631 qFatal("In file %s, line %d: Out of memory", n, l);
1635 Allows you to throw an exception without including <new>
1636 Called internally from Q_CHECK_PTR on certain OS combinations
1640 QT_THROW(std::bad_alloc());
1644 The Q_ASSERT macro calls this function when the test fails.
1646 void qt_assert(const char *assertion, const char *file, int line)
1648 qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
1652 The Q_ASSERT_X macro calls this function when the test fails.
1654 void qt_assert_x(const char *where, const char *what, const char *file, int line)
1656 qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
1661 Dijkstra's bisection algorithm to find the square root of an integer.
1662 Deliberately not exported as part of the Qt API, but used in both
1663 qsimplerichtext.cpp and qgfxraster_qws.cpp
1665 Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
1667 // n must be in the range 0...UINT_MAX/2-1
1668 if (n >= (UINT_MAX>>2)) {
1669 unsigned int r = 2 * qt_int_sqrt(n / 4);
1670 unsigned int r2 = r + 1;
1671 return (n >= r2 * r2) ? r2 : r;
1673 uint h, p= 0, q= 1, r= n;
1688 #if defined(qMemCopy)
1691 #if defined(qMemSet)
1695 void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
1696 void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
1698 #if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \
1699 defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
1701 // There are two incompatible versions of strerror_r:
1702 // a) the XSI/POSIX.1 version, which returns an int,
1703 // indicating success or not
1704 // b) the GNU version, which returns a char*, which may or may not
1705 // be the beginning of the buffer we used
1706 // The GNU libc manpage for strerror_r says you should use the the XSI
1707 // version in portable code. However, it's impossible to do that if
1708 // _GNU_SOURCE is defined so we use C++ overloading to decide what to do
1709 // depending on the return type
1710 static inline QString fromstrerror_helper(int, const QByteArray &buf)
1712 return QString::fromLocal8Bit(buf);
1714 static inline QString fromstrerror_helper(const char *str, const QByteArray &)
1716 return QString::fromLocal8Bit(str);
1721 QString qt_error_string(int errorCode)
1725 if (errorCode == -1) {
1726 #if defined(Q_OS_WIN)
1727 errorCode = GetLastError();
1732 switch (errorCode) {
1736 s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
1739 s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
1742 s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
1745 s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
1749 wchar_t *string = 0;
1750 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1753 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1757 ret = QString::fromWCharArray(string);
1758 LocalFree((HLOCAL)string);
1760 if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
1761 ret = QString::fromLatin1("The specified module could not be found.");
1762 #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
1763 QByteArray buf(1024, '\0');
1764 ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
1766 ret = QString::fromLocal8Bit(strerror(errorCode));
1771 // ######## this breaks moc build currently
1772 // ret = QCoreApplication::translate("QIODevice", s);
1773 ret = QString::fromLatin1(s);
1774 return ret.trimmed();
1777 // getenv is declared as deprecated in VS2005. This function
1778 // makes use of the new secure getenv function.
1782 Returns the value of the environment variable with name \a
1783 varName. To get the variable string, use QByteArray::constData().
1785 \note qgetenv() was introduced because getenv() from the standard
1786 C library was deprecated in VC2005 (and later versions). qgetenv()
1787 uses the new replacement function in VC, and calls the standard C
1788 library's implementation on all other platforms.
1792 QByteArray qgetenv(const char *varName)
1794 #if defined(_MSC_VER) && _MSC_VER >= 1400
1795 size_t requiredSize = 0;
1797 getenv_s(&requiredSize, 0, 0, varName);
1798 if (requiredSize == 0)
1800 buffer.resize(int(requiredSize));
1801 getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
1802 // requiredSize includes the terminating null, which we don't want.
1803 Q_ASSERT(buffer.endsWith('\0'));
1807 return QByteArray(::getenv(varName));
1814 This function sets the \a value of the environment variable named
1815 \a varName. It will create the variable if it does not exist. It
1816 returns 0 if the variable could not be set.
1818 \note qputenv() was introduced because putenv() from the standard
1819 C library was deprecated in VC2005 (and later versions). qputenv()
1820 uses the replacement function in VC, and calls the standard C
1821 library's implementation on all other platforms.
1825 bool qputenv(const char *varName, const QByteArray& value)
1827 #if defined(_MSC_VER) && _MSC_VER >= 1400
1828 return _putenv_s(varName, value.constData()) == 0;
1830 QByteArray buffer(varName);
1833 char* envVar = qstrdup(buffer.constData());
1834 int result = putenv(envVar);
1835 if (result != 0) // error. we have to delete the string.
1841 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1843 # if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
1844 // older versions of INTEGRITY used a long instead of a uint for the seed.
1845 typedef long SeedStorageType;
1847 typedef uint SeedStorageType;
1850 typedef QThreadStorage<SeedStorageType *> SeedStorage;
1851 Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value
1859 Thread-safe version of the standard C++ \c srand() function.
1861 Sets the argument \a seed to be used to generate a new random number sequence of
1862 pseudo random integers to be returned by qrand().
1864 The sequence of random numbers generated is deterministic per thread. For example,
1865 if two threads call qsrand(1) and subsequently calls qrand(), the threads will get
1866 the same random number sequence.
1870 void qsrand(uint seed)
1872 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1873 SeedStorage *seedStorage = randTLS();
1875 SeedStorageType *pseed = seedStorage->localData();
1877 seedStorage->setLocalData(pseed = new SeedStorageType);
1880 //global static seed storage should always exist,
1881 //except after being deleted by QGlobalStaticDeleter.
1882 //But since it still can be called from destructor of another
1883 //global static object, fallback to srand(seed)
1887 // On Windows srand() and rand() already use Thread-Local-Storage
1888 // to store the seed between calls
1889 // this is also valid for QT_NO_THREAD
1898 Thread-safe version of the standard C++ \c rand() function.
1900 Returns a value between 0 and \c RAND_MAX (defined in \c <cstdlib> and
1901 \c <stdlib.h>), the next number in the current sequence of pseudo-random
1904 Use \c qsrand() to initialize the pseudo-random number generator with
1911 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1912 SeedStorage *seedStorage = randTLS();
1914 SeedStorageType *pseed = seedStorage->localData();
1916 seedStorage->setLocalData(pseed = new SeedStorageType);
1919 return rand_r(pseed);
1921 //global static seed storage should always exist,
1922 //except after being deleted by QGlobalStaticDeleter.
1923 //But since it still can be called from destructor of another
1924 //global static object, fallback to rand()
1928 // On Windows srand() and rand() already use Thread-Local-Storage
1929 // to store the seed between calls
1930 // this is also valid for QT_NO_THREAD
1939 This macro is provided for convenience for writing infinite
1944 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 31
1946 It is equivalent to \c{for (;;)}.
1948 If you're worried about namespace pollution, you can disable this
1949 macro by adding the following line to your \c .pro file:
1951 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 32
1960 Same as \l{forever}.
1962 This macro is available even when \c no_keywords is specified
1963 using the \c .pro file's \c CONFIG variable.
1969 \macro foreach(variable, container)
1972 This macro is used to implement Qt's \c foreach loop. The \a
1973 variable parameter is a variable name or variable definition; the
1974 \a container parameter is a Qt container whose value type
1975 corresponds to the type of the variable. See \l{The foreach
1976 Keyword} for details.
1978 If you're worried about namespace pollution, you can disable this
1979 macro by adding the following line to your \c .pro file:
1981 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 33
1987 \macro Q_FOREACH(variable, container)
1990 Same as foreach(\a variable, \a container).
1992 This macro is available even when \c no_keywords is specified
1993 using the \c .pro file's \c CONFIG variable.
1999 \macro QT_TR_NOOP(sourceText)
2002 Marks the string literal \a sourceText for dynamic translation in
2003 the current context (class), i.e the stored \a sourceText will not
2006 The macro expands to \a sourceText.
2010 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 34
2012 The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
2013 that the source string is encoded in UTF-8. Corresponding variants
2014 exist in the QT_TRANSLATE_NOOP() family of macros, too. Note that
2015 using these macros is not required if \c CODECFORTR is already set to
2016 UTF-8 in the qmake project file.
2018 \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2022 \macro QT_TRANSLATE_NOOP(context, sourceText)
2025 Marks the string literal \a sourceText for dynamic translation in
2026 the given \a context; i.e, the stored \a sourceText will not be
2027 altered. The \a context is typically a class and also needs to
2028 be specified as string literal.
2030 The macro expands to \a sourceText.
2034 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 35
2036 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
2040 \macro QT_TRANSLATE_NOOP3(context, sourceText, comment)
2044 Marks the string literal \a sourceText for dynamic translation in the
2045 given \a context and with \a comment, i.e the stored \a sourceText will
2046 not be altered. The \a context is typically a class and also needs to
2047 be specified as string literal. The string literal \a comment
2048 will be available for translators using e.g. Qt Linguist.
2050 The macro expands to anonymous struct of the two string
2051 literals passed as \a sourceText and \a comment.
2055 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 36
2057 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2061 \fn QString qtTrId(const char *id, int n = -1)
2066 \brief The qtTrId function finds and returns a translated string.
2068 Returns a translated string identified by \a id.
2069 If no matching string is found, the id itself is returned. This
2070 should not happen under normal conditions.
2072 If \a n >= 0, all occurrences of \c %n in the resulting string
2073 are replaced with a decimal representation of \a n. In addition,
2074 depending on \a n's value, the translation text may vary.
2076 Meta data and comments can be passed as documented for QObject::tr().
2077 In addition, it is possible to supply a source string template like that:
2083 \tt{\begincomment% <C string> \endcomment}
2087 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid
2089 Creating QM files suitable for use with this function requires passing
2090 the \c -idbased option to the \c lrelease tool.
2092 \warning This method is reentrant only if all translators are
2093 installed \e before calling this method. Installing or removing
2094 translators while performing translations is not supported. Doing
2095 so will probably result in crashes or other undesirable behavior.
2097 \sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
2101 \macro QT_TRID_NOOP(id)
2105 \brief The QT_TRID_NOOP macro marks an id for dynamic translation.
2107 The only purpose of this macro is to provide an anchor for attaching
2108 meta data like to qtTrId().
2110 The macro expands to \a id.
2114 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid_noop
2116 \sa qtTrId(), {Internationalization with Qt}
2120 \macro Q_LIKELY(expr)
2124 \brief Hints to the compiler that the enclosed condition, \a expr, is
2125 likely to evaluate to \c true.
2127 Use of this macro can help the compiler to optimize the code.
2131 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qlikely
2137 \macro Q_UNLIKELY(expr)
2141 \brief Hints to the compiler that the enclosed condition, \a expr, is
2142 likely to evaluate to \c false.
2144 Use of this macro can help the compiler to optimize the code.
2148 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunlikely
2154 \macro QT_POINTER_SIZE
2157 Expands to the size of a pointer in bytes (4 or 8). This is
2158 equivalent to \c sizeof(void *) but can be used in a preprocessor
2167 Synonym for \c true.
2177 Synonym for \c false.
2187 Use qAbs(\a n) instead.
2197 Use qMin(\a x, \a y) instead.
2207 Use qMax(\a x, \a y) instead.
2213 \macro const char *qPrintable(const QString &str)
2216 Returns \a str as a \c{const char *}. This is equivalent to
2217 \a{str}.toLocal8Bit().constData().
2219 The char pointer will be invalid after the statement in which
2220 qPrintable() is used. This is because the array returned by
2221 toLocal8Bit() will fall out of scope.
2225 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 37
2228 \sa qDebug(), qWarning(), qCritical(), qFatal()
2232 \macro Q_DECLARE_TYPEINFO(Type, Flags)
2235 You can use this macro to specify information about a custom type
2236 \a Type. With accurate type information, Qt's \l{Container Classes}
2237 {generic containers} can choose appropriate storage methods and
2240 \a Flags can be one of the following:
2243 \o \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
2244 data) type with no constructor or destructor.
2245 \o \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
2246 and/or a destructor but can be moved in memory using \c
2248 \o \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
2249 constructors and/or a destructor and that it may not be moved
2253 Example of a "primitive" type:
2255 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38
2257 Example of a movable type:
2259 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39
2263 \macro Q_UNUSED(name)
2266 Indicates to the compiler that the parameter with the specified
2267 \a name is not used in the body of a function. This can be used to
2268 suppress compiler warnings while allowing functions to be defined
2269 with meaningful parameter names in their signatures.
2272 struct QInternal_CallBackTable {
2273 QVector<QList<qInternalCallback> > callbacks;
2276 Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
2278 bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
2280 if (cb >= 0 && cb < QInternal::LastCallback) {
2281 QInternal_CallBackTable *cbt = global_callback_table();
2282 cbt->callbacks.resize(cb + 1);
2283 cbt->callbacks[cb].append(callback);
2289 bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
2291 if (cb >= 0 && cb < QInternal::LastCallback) {
2292 QInternal_CallBackTable *cbt = global_callback_table();
2293 return (bool) cbt->callbacks[cb].removeAll(callback);
2298 bool QInternal::activateCallbacks(Callback cb, void **parameters)
2300 Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
2302 QInternal_CallBackTable *cbt = global_callback_table();
2303 if (cbt && cb < cbt->callbacks.size()) {
2304 QList<qInternalCallback> callbacks = cbt->callbacks[cb];
2306 for (int i=0; i<callbacks.size(); ++i)
2307 ret |= (callbacks.at(i))(parameters);
2317 This macro can be used to determine the byte order your system
2318 uses for storing data in memory. i.e., whether your system is
2319 little-endian or big-endian. It is set by Qt to one of the macros
2320 Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
2321 about endian-ness, but you might, for example if you need to know
2322 which byte of an integer or UTF-16 character is stored in the
2323 lowest address. Endian-ness is important in networking, where
2324 computers with different values for Q_BYTE_ORDER must pass data
2327 Use this macro as in the following examples.
2329 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 40
2331 \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
2335 \macro Q_LITTLE_ENDIAN
2338 This macro represents a value you can compare to the macro
2339 Q_BYTE_ORDER to determine the endian-ness of your system. In a
2340 little-endian system, the least significant byte is stored at the
2341 lowest address. The other bytes follow in increasing order of
2344 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 41
2346 \sa Q_BYTE_ORDER, Q_BIG_ENDIAN
2353 This macro represents a value you can compare to the macro
2354 Q_BYTE_ORDER to determine the endian-ness of your system. In a
2355 big-endian system, the most significant byte is stored at the
2356 lowest address. The other bytes follow in decreasing order of
2359 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 42
2361 \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
2365 \macro Q_GLOBAL_STATIC(type, name)
2368 Declares a global static variable with the given \a type and \a name.
2370 Use this macro to instantiate an object in a thread-safe way, creating
2371 a global pointer that can be used to refer to it.
2373 \warning This macro is subject to a race condition that can cause the object
2374 to be constructed twice. However, if this occurs, the second instance will
2375 be immediately deleted.
2378 \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2379 by Scott Meyers and Andrei Alexandrescu.
2383 \macro Q_GLOBAL_STATIC_WITH_ARGS(type, name, arguments)
2386 Declares a global static variable with the specified \a type and \a name.
2388 Use this macro to instantiate an object using the \a arguments specified
2389 in a thread-safe way, creating a global pointer that can be used to refer
2392 \warning This macro is subject to a race condition that can cause the object
2393 to be constructed twice. However, if this occurs, the second instance will
2394 be immediately deleted.
2397 \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2398 by Scott Meyers and Andrei Alexandrescu.
2405 If this macro is defined to \c ns all Qt classes are put in a namespace
2406 called \c ns. Also, moc will output code putting metaobjects etc.
2407 into namespace \c ns.
2409 \sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
2410 QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
2411 QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
2412 QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
2416 \macro QT_PREPEND_NAMESPACE(identifier)
2419 This macro qualifies \a identifier with the full namespace.
2420 It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
2421 and only \a identifier otherwise.
2427 \macro QT_USE_NAMESPACE
2430 This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
2431 and nothing otherwise.
2437 \macro QT_BEGIN_NAMESPACE
2440 This macro expands to
2442 \snippet snippets/code/src_corelib_global_qglobal.cpp begin namespace macro
2444 if \c QT_NAMESPACE is defined and nothing otherwise. If should always
2445 appear in the file-level scope and be followed by \c QT_END_NAMESPACE
2446 at the same logical level with respect to preprocessor conditionals
2449 As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
2450 and Qt source files after the last \c{#include} line and before the first
2451 declaration. In Qt headers using \c QT_BEGIN_HEADER, \c QT_BEGIN_NAMESPACE
2452 follows \c QT_BEGIN_HEADER immediately.
2454 If that rule can't be followed because, e.g., \c{#include} lines and
2455 declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
2456 the first declaration and wrap the \c{#include} lines in
2457 \c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
2459 When using the \c QT_NAMESPACE feature in user code
2460 (e.g., when building plugins statically linked to Qt) where
2461 the user code is not intended to go into the \c QT_NAMESPACE
2462 namespace, all forward declarations of Qt classes need to
2463 be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
2464 After that, a \c QT_USE_NAMESPACE should follow.
2465 No further changes should be needed.
2471 \macro QT_END_NAMESPACE
2474 This macro expands to
2476 \snippet snippets/code/src_corelib_global_qglobal.cpp end namespace macro
2478 if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
2479 the effect of \c QT_BEGIN_NAMESPACE.
2481 If a source file ends with a \c{#include} directive that includes a moc file,
2482 \c QT_END_NAMESPACE should be placed before that \c{#include}.
2488 \macro QT_BEGIN_INCLUDE_NAMESPACE
2491 This macro is equivalent to \c QT_END_NAMESPACE.
2492 It only serves as syntactic sugar and is intended
2493 to be used before #include lines within a
2494 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2500 \macro QT_END_INCLUDE_NAMESPACE
2503 This macro is equivalent to \c QT_BEGIN_NAMESPACE.
2504 It only serves as syntactic sugar and is intended
2505 to be used after #include lines within a
2506 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2512 \macro QT_BEGIN_MOC_NAMESPACE
2515 This macro is output by moc at the beginning of
2516 moc files. It is equivalent to \c QT_USE_NAMESPACE.
2522 \macro QT_END_MOC_NAMESPACE
2525 This macro is output by moc at the beginning of
2526 moc files. It expands to nothing.
2532 \fn bool qFuzzyCompare(double p1, double p2)
2537 Compares the floating point value \a p1 and \a p2 and
2538 returns \c true if they are considered equal, otherwise \c false.
2540 Note that comparing values where either \a p1 or \a p2 is 0.0 will not work.
2541 The solution to this is to compare against values greater than or equal to 1.0.
2543 \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46
2545 The two numbers are compared in a relative way, where the
2546 exactness is stronger the smaller the numbers are.
2550 \fn bool qFuzzyCompare(float p1, float p2)
2555 Compares the floating point value \a p1 and \a p2 and
2556 returns \c true if they are considered equal, otherwise \c false.
2558 The two numbers are compared in a relative way, where the
2559 exactness is stronger the smaller the numbers are.
2563 \macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
2566 This macro can be used to ensure that the application is run
2567 against a recent enough version of Qt. This is especially useful
2568 if your application depends on a specific bug fix introduced in a
2569 bug-fix release (e.g., 4.0.2).
2571 The \a argc and \a argv parameters are the \c main() function's
2572 \c argc and \c argv parameters. The \a version parameter is a
2573 string literal that specifies which version of Qt the application
2574 requires (e.g., "4.0.2").
2578 \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 4
2582 \macro Q_DECL_EXPORT
2585 This macro marks a symbol for shared library export (see
2586 \l{sharedlibrary.html}{Creating Shared Libraries}).
2592 \macro Q_DECL_IMPORT
2595 This macro declares a symbol to be an import from a shared library (see
2596 \l{sharedlibrary.html}{Creating Shared Libraries}).
2602 \macro Q_DECL_CONSTEXPR
2605 This macro can be used to declare variable that should be constructed at compile-time,
2606 or an inline function that can be computed at compile-time.
2608 It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing