<QtGlobal> - Global Qt DeclarationsThe <QtGlobal> header file includes the fundamental global declarations. It is included by most other Qt header files. More... Types
Functions
MacrosThe global declarations include types, functions and macros. The type definitions are partly convenience definitions for basic types (some of which guarantee certain bit-sizes on all platforms supported by Qt), partly types related to Qt message handling. The functions are related to generating messages, Qt version handling and comparing and adjusting object values. And finally, some of the declared macros enable programmers to add compiler or platform specific code to their applications, while others are convenience macros for larger operations. TypesThe header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for example qint8 which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. The header file also declares the qlonglong type definition for long long int (__int64 on Windows). Several convenience type definitions are declared: qreal for double, uchar for unsigned char, uint for unsigned int, ulong for unsigned long and ushort for unsigned short. Finally, the QtMsgType definition identifies the various messages that can be generated and sent to a Qt message handler; QtMessageHandler is a type definition for a pointer to a function with the signature void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *). QMessageLogContext class contains the line, file, and function the message was logged at. This information is created by the QMessageLogger class. FunctionsThe <QtGlobal> header file contains several functions comparing and adjusting an object's value. These functions take a template type as argument: You can retrieve the absolute value of an object using the qAbs() function, and you can bound a given object's value by given minimum and maximum values using the qBound() function. You can retrieve the minimum and maximum of two given objects using qMin() and qMax() respectively. All these functions return a corresponding template type; the template types can be replaced by any other type. Example: int myValue = 10; int minValue = 2; int maxValue = 6; int boundedValue = qBound(minValue, myValue, maxValue); // boundedValue == 6 <QtGlobal> also contains functions that generate messages from the given string argument: qCritical(), qDebug(), qFatal() and qWarning(). These functions call the message handler with the given message. Example: if (!driver()->isOpen() || driver()->isOpenError()) { qWarning("QSqlQuery::exec: database not open"); return false; } The remaining functions are qRound() and qRound64(), which both accept a qreal value as their argument returning the value rounded up to the nearest integer and 64-bit integer respectively, the qInstallMessageHandler() function which installs the given QtMessageHandler, and the qVersion() function which returns the version number of Qt at run-time as a string. MacrosThe <QtGlobal> header file provides a range of macros (Q_CC_*) that are defined if the application is compiled using the specified platforms. For example, the Q_CC_SUN macro is defined if the application is compiled using Forte Developer, or Sun Studio C++. The header file also declares a range of macros (Q_OS_*) that are defined for the specified platforms. For example, Q_OS_X11 which is defined for the X Window System. The purpose of these macros is to enable programmers to add compiler or platform specific code to their application. The remaining macros are convenience macros for larger operations: The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the possibility of marking text for dynamic translation, i.e. translation without changing the stored source text. The Q_ASSERT() and Q_ASSERT_X() enables warning messages of various level of refinement. The Q_FOREACH() and foreach() macros implement Qt's foreach loop. The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned 64-bit integer literals in a platform-independent way. The Q_CHECK_PTR() macro prints a warning containing the source code's file name and line number, saying that the program ran out of memory, if the pointer is 0. The qPrintable() macro represent an easy way of printing text. Finally, the QT_POINTER_SIZE macro expands to the size of a pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros expand to a numeric value or a string, respectively, specifying Qt's version number, i.e the version the application is compiled against. See also <QtAlgorithms> and QSysInfo. Type Documentation
|
Constant | Value | Description |
---|---|---|
QtDebugMsg | 0 | A message generated by the qDebug() function. |
QtWarningMsg | 1 | A message generated by the qWarning() function. |
QtCriticalMsg | 2 | A message generated by the qCritical() function. |
QtFatalMsg | 3 | A message generated by the qFatal() function. |
QtSystemMsg | QtCriticalMsg |
See also QtMessageHandler and qInstallMessageHandler().
Typedef for signed char. This type is guaranteed to be 8-bit on all platforms supported by Qt.
Typedef for signed short. This type is guaranteed to be 16-bit on all platforms supported by Qt.
Typedef for signed int. This type is guaranteed to be 32-bit on all platforms supported by Qt.
Typedef for long long int (__int64 on Windows). This type is guaranteed to be 64-bit on all platforms supported by Qt.
Literals of this type can be created using the Q_INT64_C() macro:
qint64 value = Q_INT64_C(932838457459459);
See also Q_INT64_C(), quint64, and qlonglong.
Typedef for long long int (__int64 on Windows). This is the same as qint64.
See also qulonglong and qint64.
Integral type for representing pointer differences.
Typedef for either qint32 or qint64. This type is guaranteed to be the same size as a pointer on all platforms supported by Qt. On a system with 32-bit pointers, quintptr is a typedef for quint32; on a system with 64-bit pointers, quintptr is a typedef for quint64.
Note that qptrdiff is signed. Use quintptr for unsigned values.
See also quintptr, qint32, and qint64.
Typedef for double on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms, qreal is a typedef for float for performance reasons.
Typedef for unsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt.
Typedef for unsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt.
Typedef for unsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt.
Typedef for unsigned long long int (unsigned __int64 on Windows). This type is guaranteed to be 64-bit on all platforms supported by Qt.
Literals of this type can be created using the Q_UINT64_C() macro:
quint64 value = Q_UINT64_C(932838457459459);
See also Q_UINT64_C(), qint64, and qulonglong.
Integral type for representing a pointers (useful for hashing, etc.).
Typedef for either quint32 or quint64. This type is guaranteed to be the same size as a pointer on all platforms supported by Qt. On a system with 32-bit pointers, quintptr is a typedef for quint32; on a system with 64-bit pointers, quintptr is a typedef for quint64.
Note that quintptr is unsigned. Use qptrdiff for signed values.
See also qptrdiff, quint32, and quint64.
Typedef for unsigned long long int (unsigned __int64 on Windows). This is the same as quint64.
See also quint64 and qlonglong.
Convenience typedef for unsigned char.
Convenience typedef for unsigned int.
Convenience typedef for unsigned long.
Convenience typedef for unsigned short.
Compares value to the 0 of type T and returns the absolute value. Thus if T is double, then value is compared to (double) 0.
Example:
int absoluteValue; int myValue = -4; absoluteValue = qAbs(myValue); // absoluteValue == 4
Returns value bounded by min and max. This is equivalent to qMax(min, qMin(value, max)).
Example:
int myValue = 10; int minValue = 2; int maxValue = 6; int boundedValue = qBound(minValue, myValue, maxValue); // boundedValue == 6
Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false.
Note that comparing values where either p1 or p2 is 0.0 will not work. The solution to this is to compare against values greater than or equal to 1.0.
// Instead of comparing with 0.0 qFuzzyCompare(0.0,1.0e-200); // This will return false // Compare adding 1 to both values will fix the problem qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.
Note: This function is thread-safe.
This function was introduced in Qt 4.4.
Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false.
The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.
Note: This function is thread-safe.
This function was introduced in Qt 4.4.
Returns the maximum of value1 and value2.
Example:
int myValue = 6; int yourValue = 4; int maxValue = qMax(myValue, yourValue); // maxValue == myValue
Returns the minimum of value1 and value2.
Example:
int myValue = 6; int yourValue = 4; int minValue = qMin(myValue, yourValue); // minValue == yourValue
Rounds value to the nearest 64-bit integer.
Example:
qreal valueA = 42949672960.3; qreal valueB = 42949672960.7; int roundedValueA = qRound(valueA); // roundedValueA = 42949672960 int roundedValueB = qRound(valueB); // roundedValueB = 42949672961
Rounds value to the nearest integer.
Example:
qreal valueA = 2.3; qreal valueB = 2.7; int roundedValueA = qRound(valueA); // roundedValueA = 2 int roundedValueB = qRound(valueB); // roundedValueB = 3
Returns the version number of Qt at run-time as a string (for example, "4.1.2"). This may be a different version than the version the application was compiled against.
See also QT_VERSION_STR.
Users Q_CHECK_PTR on pointer, then returns pointer.
This can be used as an inline version of Q_CHECK_PTR.
Returns the value of the environment variable with name varName. To get the variable string, use QByteArray::constData().
Note: qgetenv() was introduced because getenv() from the standard C library was deprecated in VC2005 (and later versions). qgetenv() uses the new replacement function in VC, and calls the standard C library's implementation on all other platforms.
See also qputenv().
This function sets the value of the environment variable named varName. It will create the variable if it does not exist. It returns 0 if the variable could not be set.
Note: qputenv() was introduced because putenv() from the standard C library was deprecated in VC2005 (and later versions). qputenv() uses the replacement function in VC, and calls the standard C library's implementation on all other platforms.
See also qgetenv().
Thread-safe version of the standard C++ rand() function.
Returns a value between 0 and RAND_MAX (defined in <cstdlib> and <stdlib.h>), the next number in the current sequence of pseudo-random integers.
Use qsrand() to initialize the pseudo-random number generator with a seed value.
This function was introduced in Qt 4.2.
See also qsrand().
Thread-safe version of the standard C++ srand() function.
Sets the argument seed to be used to generate a new random number sequence of pseudo random integers to be returned by qrand().
The sequence of random numbers generated is deterministic per thread. For example, if two threads call qsrand(1) and subsequently calls qrand(), the threads will get the same random number sequence.
This function was introduced in Qt 4.2.
See also qrand().
The qtTrId function finds and returns a translated string.
Returns a translated string identified by id. If no matching string is found, the id itself is returned. This should not happen under normal conditions.
If n >= 0, all occurrences of %n in the resulting string are replaced with a decimal representation of n. In addition, depending on n's value, the translation text may vary.
Meta data and comments can be passed as documented for QObject::tr(). In addition, it is possible to supply a source string template like that:
//% <C string>
or
\begincomment% <C string> \endcomment
Example:
//% "%n fooish bar(s) found.\n" //% "Do you want to continue?" QString text = qtTrId("qtn_foo_bar", n);
Creating QM files suitable for use with this function requires passing the -idbased option to the lrelease tool.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
Note: This function is reentrant.
This function was introduced in Qt 4.6.
See also QObject::tr(), QCoreApplication::translate(), and Internationalization with Qt.
This macro can be defined in the project file to disable functions deprecated in a specified version of Qt or any earlier version. The default version number is 5.0, meaning that functions deprecated in or before Qt 5.0 will not be included.
Examples: When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to disable functions deprecated in Qt 5.1 and earlier. In any release, set QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones deprecated in Qt 5.0
Expands to the size of a pointer in bytes (4 or 8). This is equivalent to sizeof(void *) but can be used in a preprocessor directive.
This macro can be used to ensure that the application is run against a recent enough version of Qt. This is especially useful if your application depends on a specific bug fix introduced in a bug-fix release (e.g., 4.0.2).
The argc and argv parameters are the main() function's argc and argv parameters. The version parameter is a string literal that specifies which version of Qt the application requires (e.g., "4.0.2").
Example:
#include <QApplication> #include <QMessageBox> int main(int argc, char *argv[]) { QT_REQUIRE_VERSION(argc, argv, "4.0.2") QApplication app(argc, argv); ... return app.exec(); }
Marks the string literal sourceText for dynamic translation in the given context and with comment, i.e the stored sourceText will not be altered. The context is typically a class and also needs to be specified as string literal. The string literal comment will be available for translators using e.g. Qt Linguist.
The macro expands to anonymous struct of the two string literals passed as sourceText and comment.
Example:
static { const char *source; const char *comment; } greeting_strings[] = { QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello", "A really friendly hello"), QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye", "A really friendly goodbye") }; QString FriendlyConversation::greeting(int type) { return tr(greeting_strings[type].source, greeting_strings[type].comment); } QString global_greeting(int type) { return qApp->translate("FriendlyConversation", greeting_strings[type].source, greeting_strings[type].comment); }
This function was introduced in Qt 4.4.
See also QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and Internationalization with Qt.
Marks the string literal sourceText for dynamic translation in the given context; i.e, the stored sourceText will not be altered. The context is typically a class and also needs to be specified as string literal.
The macro expands to sourceText.
Example:
static const char *greeting_strings[] = { QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") }; QString FriendlyConversation::greeting(int type) { return tr(greeting_strings[type]); } QString global_greeting(int type) { return qApp->translate("FriendlyConversation", greeting_strings[type]); }
See also QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), and Internationalization with Qt.
The QT_TRID_NOOP macro marks an id for dynamic translation.
The only purpose of this macro is to provide an anchor for attaching meta data like to qtTrId().
The macro expands to id.
Example:
static const char * const ids[] = { //% "This is the first text." QT_TRID_NOOP("qtn_1st_text"), //% "This is the second text." QT_TRID_NOOP("qtn_2nd_text"), 0 }; void TheClass::addLabels() { for (int i = 0; ids[i]; ++i) new QLabel(qtTrId(ids[i]), this); }
This function was introduced in Qt 4.6.
See also qtTrId() and Internationalization with Qt.
Marks the string literal sourceText for dynamic translation in the current context (class), i.e the stored sourceText will not be altered.
The macro expands to sourceText.
Example:
QString FriendlyConversation::greeting(int type) { static const char *greeting_strings[] = { QT_TR_NOOP("Hello"), QT_TR_NOOP("Goodbye") }; return tr(greeting_strings[type]); }
The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate that the source string is encoded in UTF-8. Corresponding variants exist in the QT_TRANSLATE_NOOP() family of macros, too.
See also QT_TRANSLATE_NOOP() and Internationalization with Qt.
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that specifies Qt's version number. For example, if you compile your application against Qt 4.1.2, the QT_VERSION macro will expand to 0x040102.
You can use QT_VERSION to use the latest Qt features where available.
Example:
#if QT_VERSION >= 0x040100 QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon); #else QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon); QIcon icon(pixmap); #endif
See also QT_VERSION_STR and qVersion().
Turns the major, minor and patch numbers of a version into an integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can be compared with another similarly processed version id.
See also QT_VERSION.
This macro expands to a string that specifies Qt's version number (for example, "4.1.2"). This is the version against which the application is compiled.
See also qVersion() and QT_VERSION.
Prints a warning message containing the source code file name and line number if test is false.
Q_ASSERT() is useful for testing pre- and post-conditions during development. It does nothing if QT_NO_DEBUG was defined during compilation.
Example:
// File: div.cpp #include <QtGlobal> int divide(int a, int b) { Q_ASSERT(b != 0); return a / b; }
If b is zero, the Q_ASSERT statement will output the following message using the qFatal() function:
ASSERT: "b == 0" in file div.cpp, line 7
See also Q_ASSERT_X(), qFatal(), and Debugging Techniques.
Prints the message what together with the location where, the source file name and line number if test is false.
Q_ASSERT_X is useful for testing pre- and post-conditions during development. It does nothing if QT_NO_DEBUG was defined during compilation.
Example:
// File: div.cpp #include <QtGlobal> int divide(int a, int b) { Q_ASSERT_X(b != 0, "divide", "division by zero"); return a / b; }
If b is zero, the Q_ASSERT_X statement will output the following message using the qFatal() function:
ASSERT failure in divide: "division by zero", file div.cpp, line 7
See also Q_ASSERT(), qFatal(), and Debugging Techniques.
Causes the compiler to assume that expr is true. This macro is useful for improving code generation, by providing the compiler with hints about conditions that it would not otherwise know about. However, there is no guarantee that the compiler will actually use those hints.
This macro could be considered a "lighter" version of Q_ASSERT. While Q_ASSERT will abort the program's execution if the condition is false, Q_ASSUME will tell the compiler not to generate code for those conditions. Therefore, it is important that the assumptions always hold, otherwise undefined behaviour may occur.
If expr is a constantly false condition, Q_ASSUME will tell the compiler that the current code execution cannot be reached. That is, Q_ASSUME(false) is equivalent to Q_UNREACHABLE().
Note: Q_LIKELY() tells the compiler that the expression is likely, but not the only possibility. Q_ASSUME tells the compiler that it is the only possibility.
This function was introduced in Qt 5.0.
See also Q_ASSERT(), Q_UNREACHABLE(), and Q_LIKELY().
This macro represents a value you can compare to the macro Q_BYTE_ORDER to determine the endian-ness of your system. In a big-endian system, the most significant byte is stored at the lowest address. The other bytes follow in decreasing order of significance.
#if Q_BYTE_ORDER == Q_BIG_ENDIAN ... #endif
See also Q_BYTE_ORDER and Q_LITTLE_ENDIAN.
This macro can be used to determine the byte order your system uses for storing data in memory. i.e., whether your system is little-endian or big-endian. It is set by Qt to one of the macros Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry about endian-ness, but you might, for example if you need to know which byte of an integer or UTF-16 character is stored in the lowest address. Endian-ness is important in networking, where computers with different values for Q_BYTE_ORDER must pass data back and forth.
Use this macro as in the following examples.
#if Q_BYTE_ORDER == Q_BIG_ENDIAN ... #endif or #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN ... #endif
See also Q_BIG_ENDIAN and Q_LITTLE_ENDIAN.
Defined if the application is compiled using Borland/Turbo C++.
Defined if the application is compiled using Reliant C++.
Defined if the application is compiled using Comeau C++.
Defined if the application is compiled using DEC C++.
Defined if the application is compiled using Edison Design Group C++.
Defined if the application is compiled using Green Hills Optimizing C++ Compilers.
Defined if the application is compiled using GNU C++.
Defined if the application is compiled using MetaWare High C/C++.
Defined if the application is compiled using HP aC++.
Defined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows.
Defined if the application is compiled using KAI C++.
Defined if the application is compiled using MIPSpro C++.
Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.
Defined if the application is compiled using CenterLine C++.
Defined if the application is compiled using Portland Group C++.
Defined if the application is compiled using Forte Developer, or Sun Studio C++.
Defined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++).
Defined if the application is compiled using SCO OUDK and UDK.
Defined if the application is compiled using Watcom C++.
If pointer is 0, prints a warning message containing the source code's file name and line number, saying that the program ran out of memory.
Q_CHECK_PTR does nothing if QT_NO_DEBUG was defined during compilation.
Example:
int *a; Q_CHECK_PTR(a = new int[80]); // WRONG! a = new (nothrow) int[80]; // Right Q_CHECK_PTR(a);
See also qWarning() and Debugging Techniques.
You can use this macro to specify information about a custom type Type. With accurate type information, Qt's generic containers can choose appropriate storage methods and algorithms.
Flags can be one of the following:
Example of a "primitive" type:
struct Point2D { int x; int y; }; Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);
An example of a non-POD "primitive" type is QUuid: Even though QUuid has constructors (and therefore isn't POD), every bit pattern still represents a valid object, and memcpy() can be used to create a valid independent copy of a QUuid object.
Example of a movable type:
class Point2D { public: Point2D() { data = new int[2]; } Point2D(const Point2D &other) { ... } ~Point2D() { delete[] data; } Point2D &operator=(const Point2D &other) { ... } int x() const { return data[0]; } int y() const { return data[1]; } private: int *data; }; Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE);
This macro can be used to declare variable that should be constructed at compile-time, or an inline function that can be computed at compile-time.
It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing otherwise.
This macro marks a symbol for shared library export (see Creating Shared Libraries).
See also Q_DECL_IMPORT.
This macro declares a symbol to be an import from a shared library (see Creating Shared Libraries).
See also Q_DECL_EXPORT.
Same as foreach(variable, container).
This macro is available even when no_keywords is specified using the .pro file's CONFIG variable.
See also foreach().
Same as forever.
This macro is available even when no_keywords is specified using the .pro file's CONFIG variable.
See also foreach().
Expands to a string that describe the function the macro resides in. How this string looks more specifically is compiler dependent. With GNU GCC it is typically the function signature, while with other compilers it might be the line and column number.
Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
template<typename TInputType> const TInputType &myMin(const TInputType &value1, const TInputType &value2) { qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; if(value1 < value2) return value1; else return value2; }
when instantiated with the integer type, will with the GCC compiler produce:
const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4
If this macro is used outside a function, the behavior is undefined.
Wraps the signed 64-bit integer literal in a platform-independent way.
Example:
qint64 value = Q_INT64_C(932838457459459);
See also qint64 and Q_UINT64_C().
Hints to the compiler that the enclosed condition, expr, is likely to evaluate to true.
Use of this macro can help the compiler to optimize the code.
Example:
// the condition inside the "if" will be successful most of the times for (int i = 1; i <= 365; i++) { if (Q_LIKELY(isWorkingDay(i))) { ... } ... }
This function was introduced in Qt 4.8.
See also Q_UNLIKELY().
This macro represents a value you can compare to the macro Q_BYTE_ORDER to determine the endian-ness of your system. In a little-endian system, the least significant byte is stored at the lowest address. The other bytes follow in increasing order of significance.
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN ... #endif
See also Q_BYTE_ORDER and Q_BIG_ENDIAN.
Defined on AIX.
Defined on Any BSD 4.4 system.
Defined on BSD/OS.
Defined on Cygwin.
Defined on Darwin OS (synonym for Q_OS_MAC).
Defined on DG/UX.
Defined on DYNIX/ptx.
Defined on FreeBSD.
Defined on HP-UX.
Defined on GNU Hurd.
Defined on SGI Irix.
Defined on Linux.
Defined on LynxOS.
Defined on MAC OS (synonym for Darwin).
Defined on NetBSD.
Defined on OpenBSD.
Defined on HP Tru64 UNIX.
Defined on QNX Neutrino.
Defined on Reliant UNIX.
Defined on SCO OpenServer 5.
Defined on Sun Solaris.
Defined on DEC Ultrix.
Defined on Any UNIX BSD/SYSV system.
Defined on UnixWare 7, Open UNIX 8.
Defined on all supported versions of Windows.
Defined on Windows CE.
Defined if the application is compiled for x86 processors. Qt currently supports two x86 variants: Q_PROCESSOR_X86_32 and Q_PROCESSOR_X86_64.
Defined if the application is compiled for S/390 processors. Qt supports one optional variant of S/390: Q_PROCESSOR_S390_X.
Defined if the application is compiled for Alpha processors.
Defined if the application is compiled for ARM processors. Qt currently supports three optional ARM revisions: Q_PROCESSOR_ARM_V5, Q_PROCESSOR_ARM_V6, and Q_PROCESSOR_ARM_V7.
Defined if the application is compiled for ARMv5 processors. The Q_PROCESSOR_ARM macro is also defined when Q_PROCESSOR_ARM_V5 is defined.
Defined if the application is compiled for ARMv6 processors. The Q_PROCESSOR_ARM and Q_PROCESSOR_ARM_V5 macros are also defined when Q_PROCESSOR_ARM_V6 is defined.
Defined if the application is compiled for ARMv7 processors. The Q_PROCESSOR_ARM, Q_PROCESSOR_ARM_V5, and Q_PROCESSOR_ARM_V6 macros are also defined when Q_PROCESSOR_ARM_V7 is defined.
Defined if the application is compiled for AVR32 processors.
Defined if the application is compiled for Blackfin processors.
Defined if the application is compiled for IA-64 processors. This includes all Itanium and Itanium 2 processors.
Defined if the application is compiled for MIPS processors. Qt currently supports seven MIPS revisions: Q_PROCESSOR_MIPS_I, Q_PROCESSOR_MIPS_II, Q_PROCESSOR_MIPS_III, Q_PROCESSOR_MIPS_IV, Q_PROCESSOR_MIPS_V, Q_PROCESSOR_MIPS_32, and Q_PROCESSOR_MIPS_64.
Defined if the application is compiled for MIPS32 processors. The Q_PROCESSOR_MIPS, Q_PROCESSOR_MIPS_I, and Q_PROCESSOR_MIPS_II macros are also defined when Q_PROCESSOR_MIPS_32 is defined.
Defined if the application is compiled for MIPS64 processors. The Q_PROCESSOR_MIPS, Q_PROCESSOR_MIPS_I, Q_PROCESSOR_MIPS_II, Q_PROCESSOR_MIPS_III, Q_PROCESSOR_MIPS_IV, and Q_PROCESSOR_MIPS_V macros are also defined when Q_PROCESSOR_MIPS_64 is defined.
Defined if the application is compiled for MIPS-I processors. The Q_PROCESSOR_MIPS macro is also defined when Q_PROCESSOR_MIPS_I is defined.
Defined if the application is compiled for MIPS-II processors. The Q_PROCESSOR_MIPS and Q_PROCESSOR_MIPS_I macros are also defined when Q_PROCESSOR_MIPS_II is defined.
Defined if the application is compiled for MIPS-III processors. The Q_PROCESSOR_MIPS, Q_PROCESSOR_MIPS_I, and Q_PROCESSOR_MIPS_II macros are also defined when Q_PROCESSOR_MIPS_III is defined.
Defined if the application is compiled for MIPS-IV processors. The Q_PROCESSOR_MIPS, Q_PROCESSOR_MIPS_I, Q_PROCESSOR_MIPS_II, and Q_PROCESSOR_MIPS_III macros are also defined when Q_PROCESSOR_MIPS_IV is defined.
Defined if the application is compiled for MIPS-V processors. The Q_PROCESSOR_MIPS, Q_PROCESSOR_MIPS_I, Q_PROCESSOR_MIPS_II, Q_PROCESSOR_MIPS_III, and Q_PROCESSOR_MIPS_IV macros are also defined when Q_PROCESSOR_MIPS_V is defined.
Defined if the application is compiled for POWER processors. Qt currently supports two Power variants: Q_PROCESSOR_POWER_32 and Q_PROCESSOR_POWER_64.
Defined if the application is compiled for 32-bit Power processors. The Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_32 is defined.
Defined if the application is compiled for 64-bit Power processors. The Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_64 is defined.
Defined if the application is compiled for S/390x processors. The Q_PROCESSOR_S390 macro is also defined when Q_PROCESSOR_S390_X is defined.
Defined if the application is compiled for SuperH processors. Qt currently supports one SuperH revision: Q_PROCESSOR_SH_4A.
Defined if the application is compiled for SuperH 4A processors. The Q_PROCESSOR_SH macro is also defined when Q_PROCESSOR_SH_4A is defined.
Defined if the application is compiled for SPARC processors. Qt currently supports one optional SPARC revision: Q_PROCESSOR_SPARC_V9.
Defined if the application is compiled for SPARC V9 processors. The Q_PROCESSOR_SPARC macro is also defined when Q_PROCESSOR_SPARC_V9 is defined.
Defined if the application is compiled for 32-bit x86 processors. This includes all i386, i486, i586, and i686 processors. The Q_PROCESSOR_X86 macro is also defined when Q_PROCESSOR_X86_32 is defined.
Defined if the application is compiled for 64-bit x86 processors. This includes all AMD64, Intel 64, and other x86_64/x64 processors. The Q_PROCESSOR_X86 macro is also defined when Q_PROCESSOR_X86_64 is defined.
Wraps the unsigned 64-bit integer literal in a platform-independent way.
Example:
quint64 value = Q_UINT64_C(932838457459459);
See also quint64 and Q_INT64_C().
Hints to the compiler that the enclosed condition, expr, is likely to evaluate to false.
Use of this macro can help the compiler to optimize the code.
Example:
bool readConfiguration(const QFile &file) { // We expect to be asked to read an existing file if (Q_UNLIKELY(!file.exists())) { qWarning() << "File not found"; return false; } ... return true; }
This function was introduced in Qt 4.8.
See also Q_LIKELY().
Tells the compiler that the current point cannot be reached by any execution, so it may optimise any code paths leading here as dead code, as well as code continuing from here.
This macro is useful to mark impossible conditions. For example, given the following enum:
enum Shapes { Rectangle, Triangle, Circle, NumShapes };
One can write a switch table like so:
switch (shape) { case Rectangle: return rectangle(); case Triangle: return triangle(); case Circle: return circle(); case NumShapes: Q_UNREACHABLE(); break; }
The advantage of inserting Q_UNREACHABLE() at that point is that the compiler is told not to generate code for a shape variable containing that value. If the macro is missing, the compiler will still generate the necessary comparisons for that value. If the case label were removed, some compilers could produce a warning that some enum values were not checked.
By using this macro in impossible conditions, code coverage may be improved as dead code paths may be eliminated.
This function was introduced in Qt 5.0.
See also Q_ASSERT(), Q_ASSUME(), and qFatal().
Indicates to the compiler that the parameter with the specified name is not used in the body of a function. This can be used to suppress compiler warnings while allowing functions to be defined with meaningful parameter names in their signatures.
This macro is used to implement Qt's foreach loop. The variable parameter is a variable name or variable definition; the container parameter is a Qt container whose value type corresponds to the type of the variable. See The foreach Keyword for details.
If you're worried about namespace pollution, you can disable this macro by adding the following line to your .pro file:
CONFIG += no_keywords
See also Q_FOREACH().
This macro is provided for convenience for writing infinite loops.
Example:
forever { ... }
It is equivalent to for (;;).
If you're worried about namespace pollution, you can disable this macro by adding the following line to your .pro file:
CONFIG += no_keywords
See also Q_FOREVER.
Calls the message handler with the critical message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger.
This function takes a format string and a list of arguments, similar to the C printf() function. The format should be a Latin-1 string.
Example:
void load(const QString &fileName) { QFile file(fileName); if (!file.exists()) qCritical("File '%s' does not exist!", qPrintable(fileName)); }
If you include <QtDebug>, a more convenient syntax is also available:
qCritical() << "Brush:" << myQBrush << "Other value:" << i;
A space is inserted between the items, and a newline is appended at the end.
To suppress the output at runtime, install your own message handler with qInstallMessageHandler().
See also qDebug(), qWarning(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.
Calls the message handler with the debug message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. This function does nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.
If you pass the function a format string and a list of arguments, it works in similar way to the C printf() function. The format should be a Latin-1 string.
Example:
qDebug("Items in list: %d", myList.size());
If you include <QtDebug>, a more convenient syntax is also available:
qDebug() << "Brush:" << myQBrush << "Other value:" << i;
With this syntax, the function returns a QDebug object that is configured to use the QtDebugMsg message type. It automatically puts a single space between each item, and outputs a newline at the end. It supports many C++ and Qt types.
To suppress the output at run-time, install your own message handler with qInstallMessageHandler().
See also qWarning(), qCritical(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.
Calls the message handler with the fatal message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger.
If you are using the default message handler this function will abort on Unix systems to create a core dump. On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application.
This function takes a format string and a list of arguments, similar to the C printf() function.
Example:
int divide(int a, int b) { if (b == 0) // program error qFatal("divide: cannot divide by zero"); return a / b; }
To suppress the output at runtime, install your own message handler with qInstallMessageHandler().
See also qDebug(), qCritical(), qWarning(), qInstallMessageHandler(), and Debugging Techniques.
Returns str as a const char *. This is equivalent to str.toLocal8Bit().constData().
The char pointer will be invalid after the statement in which qPrintable() is used. This is because the array returned by toLocal8Bit() will fall out of scope.
Example:
qWarning("%s: %s", qPrintable(key), qPrintable(value));
See also qDebug(), qWarning(), qCritical(), and qFatal().
Calls the message handler with the warning message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. This function does nothing if QT_NO_WARNING_OUTPUT was defined during compilation; it exits if the environment variable QT_FATAL_WARNINGS is defined.
This function takes a format string and a list of arguments, similar to the C printf() function. The format should be a Latin-1 string.
Example:
void f(int c) { if (c > 200) qWarning("f: bad argument, c == %d", c); }
If you include <QtDebug>, a more convenient syntax is also available:
qWarning() << "Brush:" << myQBrush << "Other value:" << i;
This syntax inserts a space between each item, and appends a newline at the end.
To suppress the output at runtime, install your own message handler with qInstallMessageHandler().
See also qDebug(), qCritical(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.