
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
The <QtGlobal> header file includes the fundamental global declarations. It is included by most other Qt header files.More...
| typedef | QtMsgHandler |
| enum | QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg } |
| typedef | qint8 |
| typedef | qint16 |
| typedef | qint32 |
| typedef | qint64 |
| typedef | qlonglong |
| typedef | qptrdiff |
| typedef | qreal |
| typedef | quint8 |
| typedef | quint16 |
| typedef | quint32 |
| typedef | quint64 |
| typedef | quintptr |
| typedef | qulonglong |
| typedef | uchar |
| typedef | uint |
| typedef | ulong |
| typedef | ushort |
| T | qAbs(const T & value) |
| const T & | qBound(const T & min, const T & value, const T & max) |
| void | qCritical(const char * msg, ...) |
| void | qDebug(const char * msg, ...) |
| void | qFatal(const char * msg, ...) |
| bool | qFuzzyCompare(double p1, double p2) |
| bool | qFuzzyCompare(float p1, float p2) |
| QtMsgHandler | qInstallMsgHandler(QtMsgHandler handler) |
| int | qMacVersion() |
| const T & | qMax(const T & value1, const T & value2) |
| const T & | qMin(const T & value1, const T & value2) |
| qint64 | qRound64(qreal value) |
| int | qRound(qreal value) |
| const char * | qVersion() |
| void | qWarning(const char * msg, ...) |
| T * | q_check_ptr(T * pointer) |
| QByteArray | qgetenv(const char * varName) |
| bool | qputenv(const char * varName, const QByteArray & value) |
| int | qrand() |
| void | qsrand(uint seed) |
| QString | qtTrId(const char * id, int n = -1) |
| void | qt_set_sequence_auto_mnemonic(bool on) |
| int | qt_symbian_exception2Error(const std::exception & aThrow) |
| void | qt_symbian_exception2LeaveL(const std::exception & aThrow) |
| void | qt_symbian_throwIfError(int error) |
The global declarations includetypes,functions andmacros.
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.
The header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for exampleqint8 which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. The header file also declares theqlonglong type definition forlong long int (__int64 on Windows).
Several convenience type definitions are declared:qreal fordouble,uchar forunsigned char,uint forunsigned int,ulong forunsigned long andushort forunsigned short.
Finally, theQtMsgType definition identifies the various messages that can be generated and sent to a Qt message handler;QtMsgHandler is a type definition for a pointer to a function with the signaturevoid myMsgHandler(QtMsgType, const char *).
The <QtGlobal> header file contains several functions comparing and adjusting an object's value. These functions take a template type as argument: You can retrieve the absolute value of an object using theqAbs() function, and you can bound a given object's value by given minimum and maximum values using theqBound() function. You can retrieve the minimum and maximum of two given objects usingqMin() andqMax() 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() andqWarning(). These functions call the message handler with the given message.
Example:
if (!driver()->isOpen()|| driver()->isOpenError()) {qWarning("QSqlQuery::exec: database not open");returnfalse;}
The remaining functions areqRound() andqRound64(), which both accept aqreal value as their argument returning the value rounded up to the nearest integer and 64-bit integer respectively, theqInstallMsgHandler() function which installs the givenQtMsgHandler, and theqVersion() function which returns the version number of Qt at run-time as a string.
The <QtGlobal> header file provides a range of macros (Q_CC_*) that are defined if the application is compiled using the specified platforms. For example, theQ_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_WIN32 which is defined for Microsoft Windows.
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: TheQT_TRANSLATE_NOOP() andQT_TR_NOOP() macros provide the possibility of marking text for dynamic translation, i.e. translation without changing the stored source text. TheQ_ASSERT() andQ_ASSERT_X() enables warning messages of various level of refinement. TheQ_FOREACH() andforeach() macros implement Qt's foreach loop.
TheQ_INT64_C() andQ_UINT64_C() macros wrap signed and unsigned 64-bit integer literals in a platform-independent way. TheQ_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. TheqPrintable() macro represent an easy way of printing text.
Finally, theQT_POINTER_SIZE macro expands to the size of a pointer in bytes, and theQT_VERSION andQT_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> andQSysInfo.
This is a typedef for a pointer to a function with the following signature:
void myMsgHandler(QtMsgType,constchar*);
See alsoQtMsgType andqInstallMsgHandler().
This enum describes the messages that can be sent to a message handler (QtMsgHandler). You can use the enum to identify and associate the various message types with the appropriate actions.
| Constant | Value | Description |
|---|---|---|
QtDebugMsg | 0 | A message generated by theqDebug() function. |
QtWarningMsg | 1 | A message generated by theqWarning() function. |
QtCriticalMsg | 2 | A message generated by theqCritical() function. |
QtFatalMsg | 3 | A message generated by theqFatal() function. |
QtSystemMsg | QtCriticalMsg |
See alsoQtMsgHandler andqInstallMsgHandler().
Typedef forsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt.
Typedef forsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt.
Typedef forsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt.
Typedef forlong 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 theQ_INT64_C() macro:
qint64 value=Q_INT64_C(932838457459459);
See alsoQ_INT64_C(),quint64, andqlonglong.
Typedef forlong long int (__int64 on Windows). This is the same asqint64.
See alsoqulonglong andqint64.
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 alsoquintptr,qint32, andqint64.
Typedef fordouble on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms,qreal is a typedef forfloat for performance reasons.
Typedef forunsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt.
Typedef forunsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt.
Typedef forunsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt.
Typedef forunsigned 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 theQ_UINT64_C() macro:
quint64 value=Q_UINT64_C(932838457459459);
See alsoQ_UINT64_C(),qint64, andqulonglong.
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 alsoqptrdiff,quint32, andquint64.
Typedef forunsigned long long int (unsigned __int64 on Windows). This is the same asquint64.
Convenience typedef forunsigned char.
Convenience typedef forunsigned int.
Convenience typedef forunsigned long.
Convenience typedef forunsigned short.
Comparesvalue to the 0 of type T and returns the absolute value. Thus if T isdouble, thenvalue is compared to(double) 0.
Example:
int absoluteValue;int myValue=-4;absoluteValue= qAbs(myValue);// absoluteValue == 4
Returnsvalue bounded bymin andmax. This is equivalent toqMax(min,qMin(value,max)).
Example:
int myValue=10;int minValue=2;int maxValue=6;int boundedValue= qBound(minValue, myValue, maxValue);// boundedValue == 6
Calls the message handler with the critical messagemsg. 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(constQString&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<<"Othervalue:"<< 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 withqInstallMsgHandler().
See alsoqDebug(),qWarning(),qFatal(),qInstallMsgHandler(), andDebugging Techniques.
Calls the message handler with the debug messagemsg. 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 ifQT_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 aQDebug object that is configured to use theQtDebugMsg 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 withqInstallMsgHandler().
See alsoqWarning(),qCritical(),qFatal(),qInstallMsgHandler(), andDebugging Techniques.
Calls the message handler with the fatal messagemsg. 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 thedefault 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 withqInstallMsgHandler().
See alsoqDebug(),qCritical(),qWarning(),qInstallMsgHandler(), andDebugging Techniques.
[static]boolqFuzzyCompare(double p1,double p2)Compares the floating point valuep1 andp2 and returnstrue if they are considered equal, otherwisefalse.
Note that comparing values where eitherp1 orp2 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 isthread-safe.
This function was introduced in Qt 4.4.
[static]boolqFuzzyCompare(float p1,float p2)Compares the floating point valuep1 andp2 and returnstrue if they are considered equal, otherwisefalse.
The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.
Note: This function isthread-safe.
This function was introduced in Qt 4.4.
Installs a Qt messagehandler which has been defined previously. Returns a pointer to the previous message handler (which may be 0).
The message handler is a function that prints out debug messages, warnings, critical and fatal error messages. The Qt library (debug mode) contains hundreds of warning messages that are printed when internal errors (usually invalid function arguments) occur. Qt built in release mode also contains such warnings unless QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during compilation. If you implement your own message handler, you get total control of these messages.
The default message handler prints the message to the standard output under X11 or to the debugger under Windows. If it is a fatal message, the application aborts immediately.
Only one message handler can be defined, since this is usually done on an application-wide basis to control debug output.
To restore the message handler, callqInstallMsgHandler(0).
Example:
#include <qapplication.h>#include <stdio.h>#include <stdlib.h>void myMessageOutput(QtMsgType type,constchar*msg){switch (type) {caseQtDebugMsg: fprintf(stderr,"Debug: %s\n", msg);break;caseQtWarningMsg: fprintf(stderr,"Warning: %s\n", msg);break;caseQtCriticalMsg: fprintf(stderr,"Critical: %s\n", msg);break;caseQtFatalMsg: fprintf(stderr,"Fatal: %s\n", msg); abort(); }}int main(int argc,char**argv){ qInstallMsgHandler(myMessageOutput);QApplication app(argc, argv);...return app.exec();}
See alsoqDebug(),qWarning(),qCritical(),qFatal(),QtMsgType, andDebugging Techniques.
UseQSysInfo::MacintoshVersion instead.
See alsoQSysInfo.
Returns the maximum ofvalue1 andvalue2.
Example:
int myValue=6;int yourValue=4;int maxValue= qMax(myValue, yourValue);// maxValue == myValue
Returns the minimum ofvalue1 andvalue2.
Example:
int myValue=6;int yourValue=4;int minValue= qMin(myValue, yourValue);// minValue == yourValue
Roundsvalue to the nearest 64-bit integer.
Example:
qreal valueA=42949672960.3;qreal valueB=42949672960.7;int roundedValueA=qRound(valueA);// roundedValueA = 42949672960int roundedValueB=qRound(valueB);// roundedValueB = 42949672961
Roundsvalue to the nearest integer.
Example:
qreal valueA=2.3;qreal valueB=2.7;int roundedValueA= qRound(valueA);// roundedValueA = 2int 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 alsoQT_VERSION_STR.
Calls the message handler with the warning messagemsg. 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 ifQT_NO_WARNING_OUTPUT was defined during compilation; it exits if the environment variableQT_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 withqInstallMsgHandler().
See alsoqDebug(),qCritical(),qFatal(),qInstallMsgHandler(), andDebugging Techniques.
UsersQ_CHECK_PTR onpointer, then returnspointer.
This can be used as an inline version ofQ_CHECK_PTR.
Returns the value of the environment variable with namevarName. To get the variable string, useQByteArray::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 alsoqputenv().
This function sets thevalue of the environment variable namedvarName. 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 alsoqgetenv().
Thread-safe version of the standard C++rand() function.
Returns a value between 0 andRAND_MAX (defined in<cstdlib> and<stdlib.h>), the next number in the current sequence of pseudo-random integers.
Useqsrand() to initialize the pseudo-random number generator with a seed value.
This function was introduced in Qt 4.2.
See alsoqsrand().
Thread-safe version of the standard C++srand() function.
Sets the argumentseed to be used to generate a new random number sequence of pseudo random integers to be returned byqrand().
The sequence of random numbers generated is deterministic per thread. For example, if two threads call qsrand(1) and subsequently callsqrand(), the threads will get the same random number sequence.
This function was introduced in Qt 4.2.
See alsoqrand().
The qtTrId function finds and returns a translated string.
Returns a translated string identified byid. If no matching string is found, the id itself is returned. This should not happen under normal conditions.
Ifn >= 0, all occurrences of%n in the resulting string are replaced with a decimal representation ofn. In addition, depending onn's value, the translation text may vary.
Meta data and comments can be passed as documented forQObject::tr(). In addition, it is possible to supply a source string template like that:
//% <C string>
or
/*% <C string>*/
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 thelrelease tool.
Warning: This method is reentrant only if all translators are installedbefore 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 isreentrant.
This function was introduced in Qt 4.6.
See alsoQObject::tr(),QCoreApplication::translate(), andInternationalization with Qt.
Enables automatic mnemonics on Mac ifon is true; otherwise this feature is disabled.
Note that this function is only available on Mac where mnemonics are disabled by default.
To access to this function, use an extern declaration: extern void qt_set_sequence_auto_mnemonic(bool b);
See alsoQShortcut.
Convert a caught standard C++ exceptionaThrow to a Symbian error code
Warning: This function is only available on Symbian.
See alsoqt_symbian_throwIfError() andqt_symbian_exception2LeaveL().
Convert a caught standard C++ exceptionaThrow to a Symbian leave
Warning: This function is only available on Symbian.
See alsoqt_symbian_throwIfError() andqt_symbian_exception2Error().
Throws an exception if theerror parameter is a symbian error code. This is the exception throwing equivalent of Symbian's User::LeaveIfError.
Warning: This function is only available on Symbian.
See alsoqt_symbian_exception2LeaveL() andqt_symbian_exception2Error().
Expands to the size of a pointer in bytes (4 or 8). This is equivalent tosizeof(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).
Theargc andargv parameters are themain() function'sargc andargv parameters. Theversion 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 literalsourceText for dynamic translation in the givencontext and withcomment, i.e the storedsourceText will not be altered. Thecontext is typically a class and also needs to be specified as string literal. The string literalcomment will be available for translators using e.g. Qt Linguist.
The macro expands to anonymous struct of the two string literals passed assourceText andcomment.
Example:
static {constchar*source;constchar*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 alsoQT_TR_NOOP(),QT_TRANSLATE_NOOP(), andInternationalization with Qt.
Marks the string literalsourceText for dynamic translation in the givencontext; i.e, the storedsourceText will not be altered. Thecontext is typically a class and also needs to be specified as string literal.
The macro expands tosourceText.
Example:
staticconstchar*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 alsoQT_TR_NOOP(),QT_TRANSLATE_NOOP3(), andInternationalization with Qt.
TRAP leaves from Symbianfunction and throws an appropriate standard C++ exception instead. This must be used when calling Symbian OS leaving functions from inside Qt or standard C++ code, so that the code can respond correctly to the exception.
Warning: This macro is only available on Symbian.
Example:
// A Symbian leaving function is being called within a Qt function.// Any leave must be converted to an exceptionCAknTitlePane* titlePane= S60->titlePane();if (titlePane) { TPtrC captionPtr(qt_QString2TPtrC(caption)); QT_TRAP_THROWING(titlePane->SetTextL(captionPtr));}
See alsoQT_TRYCATCH_ERROR() andQT_TRYCATCH_LEAVING().
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 toqtTrId().
The macro expands toid.
Example:
staticconstchar*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)newQLabel(qtTrId(ids[i]),this);}
This function was introduced in Qt 4.6.
See alsoqtTrId() andInternationalization with Qt.
Catch standard C++ exceptions from afunction and convert them to a Symbian OSerror code, orKErrNone if there is no exception. This must be used inside Qt or standard C++ code when using exception throwing code (practically anything) and returning an error code to Symbian OS.
Warning: This macro is only available on Symbian.
Example:
// An exception might be thrown in this Symbian TInt error returning function.// It is caught and translated to an error codeTIntQServerApp::Connect(constQString&serverName){ TPtrC name; TInt err; QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName)));if (err!= KErrNone)return err;return iServer.Connect(name);}
}
See alsoQT_TRYCATCH_LEAVING() andQT_TRAP_THROWING().
Catch standard C++ exceptions fromfunction and convert them to Symbian OS leaves. This must be used inside Qt or standard C++ code when using exception throwing code (practically anything) and returning to Symbian OS from a leaving function. For example inside a Symbian active object'sRunL function implemented with Qt code.
Warning: This macro is only available on Symbian.
Example:
// This active object signals Qt code// Exceptions from the Qt code must be converted to Symbian OS leaves for the active schedulervoidQWakeUpActiveObject::RunL(){ iStatus= KRequestPending; SetActive(); QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled());}
See alsoQT_TRAP_THROWING() andQT_TRYCATCH_ERROR().
Marks the string literalsourceText for dynamic translation in the current context (class), i.e the storedsourceText will not be altered.
The macro expands tosourceText.
Example:
QString FriendlyConversation::greeting(int type){staticconstchar*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 theQT_TRANSLATE_NOOP() family of macros, too. Note that using these macros is not required ifCODECFORTR is already set to UTF-8 in the qmake project file.
See alsoQT_TRANSLATE_NOOP() andInternationalization 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, theQT_VERSION macro will expand to 0x040102.
You can useQT_VERSION to use the latest Qt features where available.
Example:
#if QT_VERSION >= 0x040100QIcon icon= style()->standardIcon(QStyle::SP_TrashIcon);#elseQPixmap pixmap= style()->standardPixmap(QStyle::SP_TrashIcon);QIcon icon(pixmap);#endif
See alsoQT_VERSION_STR andqVersion().
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 alsoQT_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 alsoqVersion() andQT_VERSION.
Prints a warning message containing the source code file name and line number iftest is false.
Q_ASSERT() is useful for testing pre- and post-conditions during development. It does nothing ifQT_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;}
Ifb is zero, the Q_ASSERT statement will output the following message using theqFatal() function:
ASSERT:"b == 0" in file div.cpp, line7
See alsoQ_ASSERT_X(),qFatal(), andDebugging Techniques.
Prints the messagewhat together with the locationwhere, the source file name and line number iftest is false.
Q_ASSERT_X is useful for testing pre- and post-conditions during development. It does nothing ifQT_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;}
Ifb is zero, the Q_ASSERT_X statement will output the following message using theqFatal() function:
ASSERT failure in divide:"division by zero", file div.cpp, line7
See alsoQ_ASSERT(),qFatal(), andDebugging Techniques.
This macro represents a value you can compare to the macroQ_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 alsoQ_BYTE_ORDER andQ_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 macrosQ_LITTLE_ENDIAN orQ_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...#endifor#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN...#endif
See alsoQ_BIG_ENDIAN andQ_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 Metrowerks CodeWarrior.
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++.
Ifpointer 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 ifQT_NO_DEBUG was defined during compilation.
Example:
int*a;Q_CHECK_PTR(a=newint[80]);// WRONG!a=new (nothrow)int[80];// RightQ_CHECK_PTR(a);
See alsoqWarning() andDebugging Techniques.
You can use this macro to specify information about a custom typeType. With accurate type information, Qt'sgeneric containers can choose appropriate storage methods and algorithms.
Flags can be one of the following:
Q_PRIMITIVE_TYPE specifies thatType is a POD (plain old data) type with no constructor or destructor.Q_MOVABLE_TYPE specifies thatType has a constructor and/or a destructor but can be moved in memory usingmemcpy().Q_COMPLEX_TYPE (the default) specifies thatType has constructors and/or a destructor and that it may not be moved in memory.Example of a "primitive" type:
struct Point2D{int x;int y;};Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);
Example of a movable type:
class Point2D{public: Point2D() { data=newint[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 marks a symbol for shared library export (seeCreating Shared Libraries).
See alsoQ_DECL_IMPORT.
This macro declares a symbol to be an import from a shared library (seeCreating Shared Libraries).
See alsoQ_DECL_EXPORT.
Same as foreach(variable,container).
This macro is available even whenno_keywords is specified using the.pro file'sCONFIG variable.
See alsoforeach().
Same asforever.
This macro is available even whenno_keywords is specified using the.pro file'sCONFIG variable.
See alsoforeach().
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 withqDebug(). 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;elsereturn 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 integerliteral in a platform-independent way.
Example:
qint64 value= Q_INT64_C(932838457459459);
See alsoqint64 andQ_UINT64_C().
Hints to the compiler that the enclosed condition,expr, is likely to evaluate totrue.
Use of this macro can help the compiler to optimize the code.
Example:
// the condition inside the "if" will be successful most of the timesfor (int i=1; i<=365; i++) {if (Q_LIKELY(isWorkingDay(i))) {... }... }
This function was introduced in Qt 4.8.
See alsoQ_UNLIKELY().
This macro represents a value you can compare to the macroQ_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 alsoQ_BYTE_ORDER andQ_BIG_ENDIAN.
Defined on AIX.
Defined on Any BSD 4.4 system.
Defined on BSD/OS.
Defined on Cygwin.
Defined on Darwin OS (synonym forQ_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 MS-DOS and Windows.
Defined on NetBSD.
Defined on OS/2.
Defined on OpenBSD.
Defined on XFree86 on OS/2 (not PM).
Defined on HP Tru64 UNIX.
Defined on QNX Neutrino.
Defined on Reliant UNIX.
Defined on SCO OpenServer 5.
Defined on Sun Solaris.
Defined on Symbian.
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.
Wraps the unsigned 64-bit integerliteral in a platform-independent way.
Example:
quint64 value= Q_UINT64_C(932838457459459);
See alsoquint64 andQ_INT64_C().
Hints to the compiler that the enclosed condition,expr, is likely to evaluate tofalse.
Use of this macro can help the compiler to optimize the code.
Example:
bool readConfiguration(constQFile&file){// We expect to be asked to read an existing fileif (Q_UNLIKELY(!file.exists())) {qWarning()<<"File not found";returnfalse; }...returntrue;}
This function was introduced in Qt 4.8.
See alsoQ_LIKELY().
Indicates to the compiler that the parameter with the specifiedname 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.
Defined on S60 with the Avkon UI framework.
See alsoQ_WS_MAC,Q_WS_WIN,Q_WS_X11, andQ_WS_QWS.
Defined on X11.
See alsoQ_WS_MAC,Q_WS_WIN,Q_WS_QWS,Q_WS_QPA, andQ_WS_S60.
Defined on Mac OS X.
See alsoQ_WS_WIN,Q_WS_X11,Q_WS_QWS,Q_WS_QPA, andQ_WS_S60.
Defined on Qt for Embedded Linux, Lite version.
See alsoQ_WS_MAC,Q_WS_WIN,Q_WS_X11,Q_WS_QWS, andQ_WS_S60.
Defined on Qt for Embedded Linux.
See alsoQ_WS_MAC,Q_WS_WIN,Q_WS_X11,Q_WS_QPA, andQ_WS_S60.
Defined on Windows.
See alsoQ_WS_MAC,Q_WS_X11,Q_WS_QWS,Q_WS_QPA, andQ_WS_S60.
This macro is used to implement Qt'sforeach loop. Thevariable parameter is a variable name or variable definition; thecontainer parameter is a Qt container whose value type corresponds to the type of the variable. SeeThe 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 alsoQ_FOREACH().
This macro is provided for convenience for writing infinite loops.
Example:
forever {...}It is equivalent tofor (;;).
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 alsoQ_FOREVER.
Returnsstr as aconst char *. This is equivalent tostr.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));
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.