<QtGlobal>

The <QtGlobal> header file includes the fundamental global declarations. It is included by most other Qt header files.

  1. #include <<QtGlobal>>

Detailed Description

The <QtGlobal> header file includes the fundamental global declarations. It is included by most other Qt header files.

The 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.

Types

The header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for example 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; QtMsgHandler is a type definition for a pointer to a function with the signature void myMsgHandler(QtMsgType, const char *).

Functions

The <QtGlobal> header file contains several functions comparing and adjusting an object's value. These functions take a template type as argument: You can retrieve the absolute value of an object using the qAbs() function, and you can bound a given object's value by given minimum and maximum values using the qBound() function. You can retrieve the minimum and maximum of two given objects using qMin() and qMax() respectively. All these functions return a corresponding template type; the template types can be replaced by any other type.

Example:

  1. int myValue = 10;
  2. int minValue = 2;
  3. int maxValue = 6;
  4.  
  5. int boundedValue = qBound(minValue, myValue, maxValue);
  6. // 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:

  1. if (!driver()->isOpen() || driver()->isOpenError())  {
  2.     qWarning("QSqlQuery::exec: database not open");
  3.     return false;
  4. }

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 qInstallMsgHandler() function which installs the given QtMsgHandler, and the qVersion() function which returns the version number of Qt at run-time as a string.

Macros

The <QtGlobal> header file provides a range of macros (Q_CC_*) that are defined if the application is compiled using the specified platforms. For example, the Q_CC_SUN macro is defined if the application is compiled using Forte Developer, or Sun Studio C++. The header file also declares a range of macros (Q_OS_*) that are defined for the specified platforms. For example, 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.

Public Types

Toggle detailsenum ::

QtMsgTypeQtMsgType { QtDebugMsg , QtWarningMsg , QtCriticalMsg , QtFatalMsg , QtSystemMsg QtCriticalMsg ...} { QtDebugMsg , QtWarningMsg , QtCriticalMsg , QtFatalMsg , QtSystemMsg QtCriticalMsg }

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.

ConstantValueDescription
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 QtMsgHandler and qInstallMsgHandler().

Look up this member in the source code.

    Types

    Toggle detailstypedef QtMsgHandlerQtMsgHandler

    This is a typedef for a pointer to a function with the following signature:

    1. void myMsgHandler(QtMsgType, const char *);

    See also QtMsgType and qInstallMsgHandler().

    Look up this member in the source code.

    Toggle detailstypedef qint8qint8

    Typedef for signed char. This type is guaranteed to be 8-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef qint16qint16

    Typedef for signed short. This type is guaranteed to be 16-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef qint32qint32

    Typedef for signed int. This type is guaranteed to be 32-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef qint64qint64

    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:

    1. qint64 value = Q_INT64_C(932838457459459);

    See also Q_INT64_C(), quint64, and qlonglong.

    Look up this member in the source code.

    Toggle detailstypedef qlonglongqlonglong

    Typedef for long long int (__int64 on Windows). This is the same as qint64.

    See also qulonglong and qint64.

    Look up this member in the source code.

    Toggle detailstypedef qptrdiffqptrdiff

    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.

    Look up this member in the source code.

    Toggle detailstypedef qrealqreal

    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.

    Look up this member in the source code.

    Toggle detailstypedef quint8quint8

    Typedef for unsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef quint16quint16

    Typedef for unsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef quint32quint32

    Typedef for unsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt.

    Look up this member in the source code.

    Toggle detailstypedef quint64quint64

    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:

    1. quint64 value = Q_UINT64_C(932838457459459);

    See also Q_UINT64_C(), qint64, and qulonglong.

    Look up this member in the source code.

    Toggle detailstypedef quintptrquintptr

    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.

    Look up this member in the source code.

    Toggle detailstypedef qulonglongqulonglong

    Typedef for unsigned long long int (unsigned __int64 on Windows). This is the same as quint64.

    See also quint64 and qlonglong.

    Look up this member in the source code.

    Toggle detailstypedef ucharuchar

    Convenience typedef for unsigned char.

    Look up this member in the source code.

    Toggle detailstypedef uintuint

    Convenience typedef for unsigned int.

    Look up this member in the source code.

    Toggle detailstypedef ulongulong

    Convenience typedef for unsigned long.

    Look up this member in the source code.

    Toggle detailstypedef ushortushort

    Convenience typedef for unsigned short.

    Look up this member in the source code.

      Public Functions

      Toggle details T

      qAbsqAbs ( const T &value ) ( const T &value )

      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:

      1. int absoluteValue;
      2. int myValue = -4;
      3.  
      4. absoluteValue = qAbs(myValue);
      5. // absoluteValue == 4

      Look up this member in the source code.

      Toggle details const T &

      qBoundqBound ( const T &min , const T &value , const T &max ...) ( const T &min , const T &value , const T &max )

      Returns value bounded by min and max. This is equivalent to qMax(min, qMin(value, max)).

      Example:

      1. int myValue = 10;
      2. int minValue = 2;
      3. int maxValue = 6;
      4.  
      5. int boundedValue = qBound(minValue, myValue, maxValue);
      6. // boundedValue == 6

      See also qMin() and qMax().

      Look up this member in the source code.

      Toggle details void

      qCriticalqCritical ( const char *msg , ... ) ( const char *msg , ... )

      Calls the message handler with the critical message msg. 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:

      1. void load(const QString &fileName)
      2.  {
      3.     QFile file(fileName);
      4.     if (!file.exists())
      5.         qCritical("File '%s' does not exist!", qPrintable(fileName));
      6. }

      If you include <QtDebug>, a more convenient syntax is also available:

      1. qCritical() << "Brush:" << myQBrush << "Other
      2. 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 qInstallMsgHandler().

      See also qDebug(), qWarning(), qFatal(), qInstallMsgHandler(), and Debugging Techniques.

      Look up this member in the source code.

      Toggle details void

      qDebugqDebug ( const char *msg , ... ) ( const char *msg , ... )

      Calls the message handler with the debug message msg. 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:

      1. qDebug("Items in list: %d", myList.size());

      If you include <QtDebug>, a more convenient syntax is also available:

      1. 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 qInstallMsgHandler().

      See also qWarning(), qCritical(), qFatal(), qInstallMsgHandler(), and Debugging Techniques.

      Look up this member in the source code.

      Toggle details void

      qFatalqFatal ( const char *msg , ... ) ( const char *msg , ... )

      Calls the message handler with the fatal message msg. 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:

      1. int divide(int a, int b)
      2.  {
      3.     if (b == 0)                                // program error
      4.         qFatal("divide: cannot divide by zero");
      5.     return a / b;
      6. }

      To suppress the output at runtime, install your own message handler with qInstallMsgHandler().

      See also qDebug(), qCritical(), qWarning(), qInstallMsgHandler(), and Debugging Techniques.

      Look up this member in the source code.

      Toggle details bool

      qFuzzyCompareqFuzzyCompare ( double p1 , double p2 ) ( double p1 , double p2 ) [static]

      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.

      1.         // Instead of comparing with 0.0
      2.                 qFuzzyCompare(0.0,1.0e-200); // This will return false
      3.         // Compare adding 1 to both values will fix the problem
      4.                 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.

      Look up this member in the source code.

      Toggle details bool

      qFuzzyCompareqFuzzyCompare ( floatp1 , floatp2 ) ( floatp1 , floatp2 ) [static]

      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.

      Look up this member in the source code.

      Toggle details QtMsgHandler

      qInstallMsgHandlerqInstallMsgHandler ( QtMsgHandler handler ...) ( QtMsgHandler handler )

      Installs a Qt message handler 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, call qInstallMsgHandler(0).

      Example:

      1. #include <qapplication.h>
      2. #include <stdio.h>
      3. #include <stdlib.h>
      4.  
      5. void myMessageOutput(QtMsgType type, const char *msg)
      6.  {
      7.     switch (type)  {
      8.     case QtDebugMsg:
      9.         fprintf(stderr, "Debug: %s\n", msg);
      10.         break;
      11.     case QtWarningMsg:
      12.         fprintf(stderr, "Warning: %s\n", msg);
      13.         break;
      14.     case QtCriticalMsg:
      15.         fprintf(stderr, "Critical: %s\n", msg);
      16.         break;
      17.     case QtFatalMsg:
      18.         fprintf(stderr, "Fatal: %s\n", msg);
      19.         abort();
      20.     }
      21. }
      22.  
      23. int main(int argc, char **argv)
      24.  {
      25.     qInstallMsgHandler(myMessageOutput);
      26.     QApplication app(argc, argv);
      27.     ...
      28.     return app.exec();
      29. }

      See also qDebug(), qWarning(), qCritical(), qFatal(), QtMsgType, and Debugging Techniques.

      Look up this member in the source code.

      Toggle details int

      qMacVersionqMacVersion () ()

      Use QSysInfo::MacintoshVersion instead.

      See also QSysInfo.

      Look up this member in the source code.

      Toggle details const T &

      qMaxqMax ( const T &value1 , const T &value2 ) ( const T &value1 , const T &value2 )

      Returns the maximum of value1 and value2.

      Example:

      1. int myValue = 6;
      2. int yourValue = 4;
      3.  
      4. int maxValue = qMax(myValue, yourValue);
      5. // maxValue == myValue

      See also qMin() and qBound().

      Look up this member in the source code.

      Toggle details const T &

      qMinqMin ( const T &value1 , const T &value2 ) ( const T &value1 , const T &value2 )

      Returns the minimum of value1 and value2.

      Example:

      1. int myValue = 6;
      2. int yourValue = 4;
      3.  
      4. int minValue = qMin(myValue, yourValue);
      5. // minValue == yourValue

      See also qMax() and qBound().

      Look up this member in the source code.

      Toggle details qint64

      qRound64qRound64 ( qreal value ) ( qreal value )

      Rounds value to the nearest 64-bit integer.

      Example:

      1.                     qreal valueA = 42949672960.3;
      2. qreal valueB = 42949672960.7;
      3.  
      4. int roundedValueA = qRound(valueA);
      5. // roundedValueA = 42949672960
      6. int roundedValueB = qRound(valueB);
      7. // roundedValueB = 42949672961

      Look up this member in the source code.

      Toggle details int

      qRoundqRound ( qreal value ) ( qreal value )

      Rounds value to the nearest integer.

      Example:

      1.                     qreal valueA = 2.3;
      2. qreal valueB = 2.7;
      3.  
      4. int roundedValueA = qRound(valueA);
      5. // roundedValueA = 2
      6. int roundedValueB = qRound(valueB);
      7. // roundedValueB = 3

      Look up this member in the source code.

      Toggle details const char *

      qVersionqVersion () ()

      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.

      Look up this member in the source code.

      Toggle details void

      qWarningqWarning ( const char *msg , ... ) ( const char *msg , ... )

      Calls the message handler with the warning message msg. 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:

      1. void f(int c)
      2.  {
      3.     if (c > 200)
      4.         qWarning("f: bad argument, c == %d", c);
      5. }

      If you include <QtDebug>, a more convenient syntax is also available:

      1. qWarning() << "Brush:" << myQBrush << "Other value:"
      2. << 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 qInstallMsgHandler().

      See also qDebug(), qCritical(), qFatal(), qInstallMsgHandler(), and Debugging Techniques.

      Look up this member in the source code.

      Toggle details T *

      q_check_ptrq_check_ptr ( T *pointer ) ( T *pointer )

      Users Q_CHECK_PTR on pointer, then returns pointer.

      This can be used as an inline version of Q_CHECK_PTR.

      Look up this member in the source code.

      Toggle details QByteArray

      qgetenvqgetenv ( const char *varName ) ( const char *varName )

      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().

      Look up this member in the source code.

      Toggle details bool

      qputenvqputenv ( const char *varName , const QByteArray &value ...) ( const char *varName , const QByteArray &value )

      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().

      Look up this member in the source code.

      Toggle details int

      qrandqrand () ()

      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.

      See also qsrand().

      Look up this member in the source code.

      Toggle details void

      qsrandqsrand ( uint seed ) ( uint seed )

      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.

      See also qrand().

      Look up this member in the source code.

      Toggle details QString

      qtTrIdqtTrId ( const char *id , int n=-1 ) ( const char *id , int n=-1 )

      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

      /*% <C string> */

      Example:

      1.     //% "%n fooish bar(s) found.\n"
      2.     //% "Do you want to continue?"
      3.     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.

      See also QObject::tr(), QCoreApplication::translate(), and Internationalization with Qt.

      Look up this member in the source code.

      Toggle details void

      qt_set_sequence_auto_mnemonicqt_set_sequence_auto_mnemonic ( bool on ) ( bool on )

      Enables automatic mnemonics on Mac if on 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 also QShortcut.

      Look up this member in the source code.

      Toggle details int

      qt_symbian_exception2Errorqt_symbian_exception2Error ( const std::exception &aThrow ...) ( const std::exception &aThrow )

      Convert a caught standard C++ exception aThrow to a Symbian error code

      Warning: This function is only available on Symbian.

      See also qt_symbian_throwIfError() and qt_symbian_exception2LeaveL().

      Look up this member in the source code.

      Toggle details void

      qt_symbian_exception2LeaveLqt_symbian_exception2LeaveL ( const std::exception &aThrow ...) ( const std::exception &aThrow )

      Convert a caught standard C++ exception aThrow to a Symbian leave

      Warning: This function is only available on Symbian.

      See also qt_symbian_throwIfError() and qt_symbian_exception2Error().

      Look up this member in the source code.

      Toggle details void

      qt_symbian_throwIfErrorqt_symbian_throwIfError ( int error ) ( int error )

      Throws an exception if the error 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 also qt_symbian_exception2LeaveL() and qt_symbian_exception2Error().

      Look up this member in the source code.

        Macros

        Toggle detailsQT_POINTER_SIZEQT_POINTER_SIZE

        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.

        Toggle detailsQT_REQUIRE_VERSIONQT_REQUIRE_VERSION ( argc , argv , version )

        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:

        1. #include <QApplication>
        2. #include <QMessageBox>
        3.  
        4. int main(int argc, char *argv[])
        5.  {
        6.     QT_REQUIRE_VERSION(argc, argv, "4.0.2")
        7.  
        8.     QApplication app(argc, argv);
        9.     ...
        10.     return app.exec();
        11. }
        Toggle detailsQT_TRANSLATE_NOOP3QT_TRANSLATE_NOOP3 ( context , sourceText , comment )

        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:

        1. static  { const char *source; const char *comment; } greeting_strings[] =
        2.  {
        3.     QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
        4.                        "A really friendly hello"),
        5.     QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
        6.                        "A really friendly goodbye")
        7. };
        8.  
        9. QString FriendlyConversation::greeting(int type)
        10.  {
        11.     return tr(greeting_strings[type].source,
        12.               greeting_strings[type].comment);
        13. }
        14.  
        15. QString global_greeting(int type)
        16.  {
        17.     return qApp->translate("FriendlyConversation",
        18.            greeting_strings[type].source,
        19.            greeting_strings[type].comment);
        20. }

        See also QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and Internationalization with Qt.

        Toggle detailsQT_TRANSLATE_NOOPQT_TRANSLATE_NOOP ( context , sourceText )

        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:

        1. static const char *greeting_strings[] =  {
        2.     QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
        3.     QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
        4. };
        5.  
        6. QString FriendlyConversation::greeting(int type)
        7.  {
        8.     return tr(greeting_strings[type]);
        9. }
        10.  
        11. QString global_greeting(int type)
        12.  {
        13.     return qApp->translate("FriendlyConversation",
        14.            greeting_strings[type]);
        15. }

        See also QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), and Internationalization with Qt.

        Toggle detailsQT_TRAP_THROWINGQT_TRAP_THROWING ( function )

        TRAP leaves from Symbian function 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:

        1. // A Symbian leaving function is being called within a Qt function.
        2. // Any leave must be converted to an exception
        3. CAknTitlePane* titlePane = S60->titlePane();
        4. if (titlePane)  {
        5.     TPtrC captionPtr(qt_QString2TPtrC(caption));
        6.     QT_TRAP_THROWING(titlePane->SetTextL(captionPtr));
        7. }

        See also QT_TRYCATCH_ERROR() and QT_TRYCATCH_LEAVING().

        Toggle detailsQT_TRID_NOOPQT_TRID_NOOP ( id )

        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:

        1. static const char * const ids[] =  {
        2.     //% "This is the first text."
        3.     QT_TRID_NOOP("qtn_1st_text"),
        4.     //% "This is the second text."
        5.     QT_TRID_NOOP("qtn_2nd_text"),
        6.     0
        7. };
        8.  
        9. void TheClass::addLabels()
        10.  {
        11.     for (int i = 0; ids[i]; ++i)
        12.         new QLabel(qtTrId(ids[i]), this);
        13. }

        See also qtTrId() and Internationalization with Qt.

        Toggle detailsQT_TRYCATCH_ERRORQT_TRYCATCH_ERROR ( error , function )

        Catch standard C++ exceptions from a function and convert them to a Symbian OS error code, or KErrNone 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:

        1. // An exception might be thrown in this Symbian TInt error returning function.
        2. // It is caught and translated to an error code
        3. TInt QServerApp::Connect(const QString &serverName)
        4.  {
        5.     TPtrC name;
        6.     TInt err;
        7.     QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName)));
        8.     if (err != KErrNone)
        9.         return err;
        10.     return iServer.Connect(name);
        11. }

        }

        See also QT_TRYCATCH_LEAVING() and QT_TRAP_THROWING().

        Toggle detailsQT_TRYCATCH_LEAVINGQT_TRYCATCH_LEAVING ( function )

        Catch standard C++ exceptions from function 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's RunL function implemented with Qt code.

        Warning: This macro is only available on Symbian.

        Example:

        1. // This active object signals Qt code
        2. // Exceptions from the Qt code must be converted to Symbian OS leaves for the active scheduler
        3. void QWakeUpActiveObject::RunL()
        4.  {
        5.     iStatus = KRequestPending;
        6.     SetActive();
        7.     QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled());
        8. }

        See also QT_TRAP_THROWING() and QT_TRYCATCH_ERROR().

        Toggle detailsQT_TR_NOOPQT_TR_NOOP ( sourceText )

        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:

        1.                     QString FriendlyConversation::greeting(int type)
        2.  {
        3. static const char *greeting_strings[] =  {
        4.     QT_TR_NOOP("Hello"),
        5.     QT_TR_NOOP("Goodbye")
        6. };
        7. return tr(greeting_strings[type]);
        8. }

        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. Note that using these macros is not required if CODECFORTR is already set to UTF-8 in the qmake project file.

        See also QT_TRANSLATE_NOOP() and Internationalization with Qt.

        Toggle detailsQT_VERSIONQT_VERSION

        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:

        1. #if QT_VERSION >= 0x040100
        2.     QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
        3. #else
        4.     QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
        5.     QIcon icon(pixmap);
        6. #endif

        See also QT_VERSION_STR and qVersion().

        Toggle detailsQT_VERSION_CHECKQT_VERSION_CHECK

        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.

        Toggle detailsQT_VERSION_STRQT_VERSION_STR

        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.

        Toggle detailsQ_ASSERTQ_ASSERT ( test )

        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:

        1. // File: div.cpp
        2.  
        3. #include <QtGlobal>
        4.  
        5. int divide(int a, int b)
        6.  {
        7.     Q_ASSERT(b != 0);
        8.     return a / b;
        9. }

        If b is zero, the Q_ASSERT statement will output the following message using the qFatal() function:

        1. ASSERT: "b == 0" in file div.cpp, line 7

        See also Q_ASSERT_X(), qFatal(), and Debugging Techniques.

        Toggle detailsQ_ASSERT_XQ_ASSERT_X ( test , where , what )

        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:

        1. // File: div.cpp
        2.  
        3. #include <QtGlobal>
        4.  
        5. int divide(int a, int b)
        6.  {
        7.     Q_ASSERT_X(b != 0, "divide", "division by zero");
        8.     return a / b;
        9. }

        If b is zero, the Q_ASSERT_X statement will output the following message using the qFatal() function:

        1. ASSERT failure in divide: "division by zero", file div.cpp, line 7

        See also Q_ASSERT(), qFatal(), and Debugging Techniques.

        Toggle detailsQ_BIG_ENDIANQ_BIG_ENDIAN

        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.

        1. #if Q_BYTE_ORDER == Q_BIG_ENDIAN
        2. ...
        3. #endif

        See also Q_BYTE_ORDER and Q_LITTLE_ENDIAN.

        Toggle detailsQ_BYTE_ORDERQ_BYTE_ORDER

        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.

        1. #if Q_BYTE_ORDER == Q_BIG_ENDIAN
        2. ...
        3. #endif
        4.  
        5. or
        6.  
        7. #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
        8. ...
        9. #endif

        See also Q_BIG_ENDIAN and Q_LITTLE_ENDIAN.

        Toggle detailsQ_CC_BORQ_CC_BOR

        Defined if the application is compiled using Borland/Turbo C++.

        Toggle detailsQ_CC_CDSQ_CC_CDS

        Defined if the application is compiled using Reliant C++.

        Toggle detailsQ_CC_COMEAUQ_CC_COMEAU

        Defined if the application is compiled using Comeau C++.

        Toggle detailsQ_CC_DECQ_CC_DEC

        Defined if the application is compiled using DEC C++.

        Toggle detailsQ_CC_EDGQ_CC_EDG

        Defined if the application is compiled using Edison Design Group C++.

        Toggle detailsQ_CC_GHSQ_CC_GHS

        Defined if the application is compiled using Green Hills Optimizing C++ Compilers.

        Toggle detailsQ_CC_GNUQ_CC_GNU

        Defined if the application is compiled using GNU C++.

        Toggle detailsQ_CC_HIGHCQ_CC_HIGHC

        Defined if the application is compiled using MetaWare High C/C++.

        Toggle detailsQ_CC_HPACCQ_CC_HPACC

        Defined if the application is compiled using HP aC++.

        Toggle detailsQ_CC_INTELQ_CC_INTEL

        Defined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows.

        Toggle detailsQ_CC_KAIQ_CC_KAI

        Defined if the application is compiled using KAI C++.

        Toggle detailsQ_CC_MIPSQ_CC_MIPS

        Defined if the application is compiled using MIPSpro C++.

        Toggle detailsQ_CC_MSVCQ_CC_MSVC

        Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.

        Toggle detailsQ_CC_MWERKSQ_CC_MWERKS

        Defined if the application is compiled using Metrowerks CodeWarrior.

        Toggle detailsQ_CC_OCQ_CC_OC

        Defined if the application is compiled using CenterLine C++.

        Toggle detailsQ_CC_PGIQ_CC_PGI

        Defined if the application is compiled using Portland Group C++.

        Toggle detailsQ_CC_SUNQ_CC_SUN

        Defined if the application is compiled using Forte Developer, or Sun Studio C++.

        Toggle detailsQ_CC_SYMQ_CC_SYM

        Defined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++).

        Toggle detailsQ_CC_USLCQ_CC_USLC

        Defined if the application is compiled using SCO OUDK and UDK.

        Toggle detailsQ_CC_WATQ_CC_WAT

        Defined if the application is compiled using Watcom C++.

        Toggle detailsQ_CHECK_PTRQ_CHECK_PTR ( pointer )

        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:

        1. int *a;
        2.  
        3. Q_CHECK_PTR(a = new int[80]);   // WRONG!
        4.  
        5. a = new (nothrow) int[80];      // Right
        6. Q_CHECK_PTR(a);

        See also qWarning() and Debugging Techniques.

        Toggle detailsQ_DECLARE_TYPEINFOQ_DECLARE_TYPEINFO ( Type , Flags )

        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:

        • Q_PRIMITIVE_TYPE specifies that Type is a POD (plain old data) type with no constructor or destructor.
        • Q_MOVABLE_TYPE specifies that Type has a constructor and/or a destructor but can be moved in memory using memcpy().
        • Q_COMPLEX_TYPE (the default) specifies that Type has constructors and/or a destructor and that it may not be moved in memory.

        Example of a "primitive" type:

        1. struct Point2D
        2.  {
        3.     int x;
        4.     int y;
        5. };
        6.  
        7. Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);

        Example of a movable type:

        1. class Point2D
        2.  {
        3. public:
        4.     Point2D()  { data = new int[2]; }
        5.     Point2D(const Point2D &other)  { ... }
        6.     ~Point2D()  { delete[] data; }
        7.  
        8.     Point2D &operator=(const Point2D &other)  { ... }
        9.  
        10.     int x() const  { return data[0]; }
        11.     int y() const  { return data[1]; }
        12.  
        13. private:
        14.     int *data;
        15. };
        16.  
        17. Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE);
        Toggle detailsQ_DECL_EXPORTQ_DECL_EXPORT

        This macro marks a symbol for shared library export (see Creating Shared Libraries).

        See also Q_DECL_IMPORT.

        Toggle detailsQ_DECL_IMPORTQ_DECL_IMPORT

        This macro declares a symbol to be an import from a shared library (see Creating Shared Libraries).

        See also Q_DECL_EXPORT.

        Toggle detailsQ_FOREACHQ_FOREACH ( variable , container )

        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().

        Toggle detailsQ_FOREVERQ_FOREVER

        Same as forever.

        This macro is available even when no_keywords is specified using the .pro file's CONFIG variable.

        See also foreach().

        Toggle detailsQ_FUNC_INFOQ_FUNC_INFO

        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:

        1. template<typename TInputType>
        2. const TInputType &myMin(const TInputType &value1, const TInputType &value2)
        3.  {
        4.     qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2;
        5.  
        6.     if(value1 < value2)
        7.         return value1;
        8.     else
        9.         return value2;
        10. }

        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.

        Toggle detailsQ_INT64_CQ_INT64_C ( literal )

        Wraps the signed 64-bit integer literal in a platform-independent way.

        Example:

        1.                     qint64 value = Q_INT64_C(932838457459459);

        See also qint64 and Q_UINT64_C().

        Toggle detailsQ_LITTLE_ENDIANQ_LITTLE_ENDIAN

        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.

        1. #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
        2. ...
        3. #endif

        See also Q_BYTE_ORDER and Q_BIG_ENDIAN.

        Toggle detailsQ_OS_AIXQ_OS_AIX

        Defined on AIX.

        Toggle detailsQ_OS_BSD4Q_OS_BSD4

        Defined on Any BSD 4.4 system.

        Toggle detailsQ_OS_BSDIQ_OS_BSDI

        Defined on BSD/OS.

        Toggle detailsQ_OS_CYGWINQ_OS_CYGWIN

        Defined on Cygwin.

        Toggle detailsQ_OS_DARWINQ_OS_DARWIN

        Defined on Darwin OS (synonym for Q_OS_MAC).

        Toggle detailsQ_OS_DGUXQ_OS_DGUX

        Defined on DG/UX.

        Toggle detailsQ_OS_DYNIXQ_OS_DYNIX

        Defined on DYNIX/ptx.

        Toggle detailsQ_OS_FREEBSDQ_OS_FREEBSD

        Defined on FreeBSD.

        Toggle detailsQ_OS_HPUXQ_OS_HPUX

        Defined on HP-UX.

        Toggle detailsQ_OS_HURDQ_OS_HURD

        Defined on GNU Hurd.

        Toggle detailsQ_OS_IRIXQ_OS_IRIX

        Defined on SGI Irix.

        Toggle detailsQ_OS_LINUXQ_OS_LINUX

        Defined on Linux.

        Toggle detailsQ_OS_LYNXQ_OS_LYNX

        Defined on LynxOS.

        Toggle detailsQ_OS_MACQ_OS_MAC

        Defined on MAC OS (synonym for Darwin).

        Toggle detailsQ_OS_MSDOSQ_OS_MSDOS

        Defined on MS-DOS and Windows.

        Toggle detailsQ_OS_NETBSDQ_OS_NETBSD

        Defined on NetBSD.

        Toggle detailsQ_OS_OS2Q_OS_OS2

        Defined on OS/2.

        Toggle detailsQ_OS_OPENBSDQ_OS_OPENBSD

        Defined on OpenBSD.

        Toggle detailsQ_OS_OS2EMXQ_OS_OS2EMX

        Defined on XFree86 on OS/2 (not PM).

        Toggle detailsQ_OS_OSFQ_OS_OSF

        Defined on HP Tru64 UNIX.

        Toggle detailsQ_OS_QNXQ_OS_QNX

        Defined on QNX Neutrino.

        Toggle detailsQ_OS_RELIANTQ_OS_RELIANT

        Defined on Reliant UNIX.

        Toggle detailsQ_OS_SCOQ_OS_SCO

        Defined on SCO OpenServer 5.

        Toggle detailsQ_OS_SOLARISQ_OS_SOLARIS

        Defined on Sun Solaris.

        Toggle detailsQ_OS_SYMBIANQ_OS_SYMBIAN

        Defined on Symbian.

        Toggle detailsQ_OS_ULTRIXQ_OS_ULTRIX

        Defined on DEC Ultrix.

        Toggle detailsQ_OS_UNIXQ_OS_UNIX

        Defined on Any UNIX BSD/SYSV system.

        Toggle detailsQ_OS_UNIXWAREQ_OS_UNIXWARE

        Defined on UnixWare 7, Open UNIX 8.

        Toggle detailsQ_OS_WIN32Q_OS_WIN32

        Defined on all supported versions of Windows.

        Toggle detailsQ_OS_WINCEQ_OS_WINCE

        Defined on Windows CE.

        Toggle detailsQ_UINT64_CQ_UINT64_C ( literal )

        Wraps the unsigned 64-bit integer literal in a platform-independent way.

        Example:

        1.                     quint64 value = Q_UINT64_C(932838457459459);

        See also quint64 and Q_INT64_C().

        Toggle detailsQ_UNUSEDQ_UNUSED ( name )

        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.

        Toggle detailsQ_WS_S60Q_WS_S60

        Defined on S60 with the Avkon UI framework.

        See also Q_WS_MAC, Q_WS_WIN, Q_WS_X11, and Q_WS_QWS.

        Toggle detailsQ_WS_X11Q_WS_X11

        Defined on X11.

        See also Q_WS_MAC, Q_WS_WIN, Q_WS_QWS, and Q_WS_S60.

        Toggle detailsQ_WS_MACQ_WS_MAC

        Defined on Mac OS X.

        See also Q_WS_WIN, Q_WS_X11, Q_WS_QWS, and Q_WS_S60.

        Toggle detailsQ_WS_QWSQ_WS_QWS

        Defined on Qt for Embedded Linux.

        See also Q_WS_MAC, Q_WS_WIN, Q_WS_X11, and Q_WS_S60.

        Toggle detailsQ_WS_WINQ_WS_WIN

        Defined on Windows.

        See also Q_WS_MAC, Q_WS_X11, Q_WS_QWS, and Q_WS_S60.

        Toggle detailsforeachforeach ( variable , container )

        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:

        1. CONFIG += no_keywords

        See also Q_FOREACH().

        Toggle detailsforeverforever

        This macro is provided for convenience for writing infinite loops.

        Example:

        1. forever  {
        2.     ...
        3. }

        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:

        1. CONFIG += no_keywords

        See also Q_FOREVER.

        Toggle detailsqPrintableqPrintable ( str )

        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:

        1. qWarning("%s: %s", qPrintable(key), qPrintable(value));

        See also qDebug(), qWarning(), qCritical(), and qFatal().

        Toggle detailsFALSEFALSEObsolete function

        Synonym for false.

        See also TRUE.

        Toggle detailsQABSQABS ( n )Obsolete function

        Use qAbs(n) instead.

        See also QMIN() and QMAX().

        Toggle detailsQMAXQMAX ( x , y )Obsolete function

        Use qMax(x, y) instead.

        See also QMIN() and QABS().

        Toggle detailsQMINQMIN ( x , y )Obsolete function

        Use qMin(x, y) instead.

        See also QMAX() and QABS().

        Toggle detailsTRUETRUEObsolete function

        Synonym for true.

        See also FALSE.

        Notes provided by the Qt Community
        Informative
        • 5

        Votes: 4

        Coverage: Qt library 4.7, 4.8, 5.0

        Picture of Tobias Hunger Tobias Hunger

        Area 51 Engineer
        2 notes

        This person works for Qt Development Frameworks. Nokia Certified Qt Developer

        environment variables

        If you need a list of all environment variables:
        Check QProcess::systemEnvironment() [developer.qt.nokia.com]

        [Revisions]