Qt:Документация 4.3.2/qtglobal

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] <QtGlobal> - Global Qt Declarations

[править] Types

[править] Functions

[править] Макросы

The 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. For 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. For 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 qInstallMsgHandler() function which installs the given QtMsgHandler, and the qVersion() 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, 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

[править]
typedef QtMsgHandler

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

 void myMsgHandler(QtMsgType, const char *);

See also QtMsgType and qInstallMsgHandler().

[править]
enum QtMsgType

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

[править]
typedef qint8

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

[править]
typedef qint16

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

[править]
typedef qint32

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

[править]
typedef qint64

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 qlonglong

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

See also qulonglong and qint64.

[править]
typedef qptrdiff

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 qreal

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 quint8

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

[править]
typedef quint16

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

[править]
typedef quint32

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

[править]
typedef quint64

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.

[править]
typedef quintptr

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 qulonglong

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

See also quint64 and qlonglong.

[править]
typedef uchar

Convenience typedef for unsigned char.

[править]
typedef uint

Convenience typedef for unsigned int.

[править]
typedef ulong

Convenience typedef for unsigned long.

[править]
typedef ushort

Convenience typedef for unsigned short.


[править] Function Documentation

[править]
T qAbs ( const T & value )

Returns the absolute value of value. For example:

 int absoluteValue;
 int myValue = -4;
 
 absoluteValue = qAbs(myValue);
 // absoluteValue == 4

[править]
const T & qBound ( 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)). For example:

 int myValue = 10;
 int minValue = 2;
 int maxValue = 6;
 
 int boundedValue = qBound(minValue, myValue, maxValue);
 // boundedValue == 6

See also qMin() and qMax().

[править]
void qCritical ( 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.

Example:

 void load(const QString &amp;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.

Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.

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

[править]
void qDebug ( 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 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.

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;

This syntax automatically puts a single space between each item, and outputs a newline at the end. It supports many C++ and Qt types.

Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.

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

[править]
void qFatal ( 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.

For a release library this function will exit the application with return value 1. For the debug version this function will abort on Unix systems to create a core dump, and report a _CRT_ERROR on Windows allowing 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;
 }

Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.

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

[править]
T qFromBigEndian ( const uchar * src )

Reads a big-endian number from memory location src and returns the number in the host byte order representation. On CPU architectures where the host byte order is little-endian (such as x86) this will swap the byte order; otherwise it will just read from src.

Note that template type T can only be an integer data type (signed or unsigned).

There are no data alignment constraints for src.

This function was introduced in Qt 4.3.

See also qFromLittleEndian(), qToBigEndian(), and qToLittleEndian().

[править]
T qFromBigEndian ( T src )

This is an overloaded member function, provided for convenience.

Converts src from big-endian byte order and returns the number in host byte order representation of that number. On CPU architectures where the host byte order is little-endian (such as x86) this will return src with the byte order swapped; otherwise it will return src unmodified.

This function was introduced in Qt 4.3.

[править]
T qFromLittleEndian ( const uchar * src )

Reads a little-endian number from memory location src and returns the number in the host byte order representation. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will swap the byte order; otherwise it will just read from src.

Note that template type T can only be an integer data type (signed or unsigned).

There are no data alignment constraints for src.

This function was introduced in Qt 4.3.

See also qFromBigEndian(), qToBigEndian(), and qToLittleEndian().

[править]
T qFromLittleEndian ( T src )

This is an overloaded member function, provided for convenience.

Converts src from little-endian byte order and returns the number in host byte order representation of that number. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will return src with the byte order swapped; otherwise it will return src unmodified.

This function was introduced in Qt 4.3.

[править]
QtMsgHandler qInstallMsgHandler ( QtMsgHandler handler )

Installs a Qt message handler which has been defined previously. Returns a pointer to the message handler.

The message handler is a function that prints out debug messages, warnings, critical and fatal error messages. The Qt library (debug version) contains hundreds of warning messages that are printed when internal errors (usually invalid function arguments) occur. 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:

 #include <qapplication.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 void myMessageOutput(QtMsgType type, const char *msg)
 {
     switch (type) {
     case QtDebugMsg:
         fprintf(stderr, "Debug: %s\n", msg);
         break;
     case QtWarningMsg:
         fprintf(stderr, "Warning: %s\n", msg);
         break;
     case QtCriticalMsg:
         fprintf(stderr, "Critical: %s\n", msg);
         break;
     case QtFatalMsg:
         fprintf(stderr, "Fatal: %s\n", msg);
         abort();
     }
 }
 
 int main(int argc, char **argv)
 {
     qInstallMsgHandler(myMessageOutput);
     QApplication app(argc, argv);
     ...
     return app.exec();
 }

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

[править]
int qMacVersion ()

Use QSysInfo::MacintoshVersion instead.

See also QSysInfo.

[править]
const T & qMax ( const T & value1, const T & value2 )

Returns the maximum of value1 and value2. For example:

 int myValue = 6;
 int yourValue = 4;
 
 int maxValue = qMax(myValue, yourValue);
 // maxValue == myValue

See also qMin() and qBound().

[править]
const T & qMin ( const T & value1, const T & value2 )

Returns the minimum of value1 and value2. For example:

 int myValue = 6;
 int yourValue = 4;
 
 int minValue = qMin(myValue, yourValue);
 // minValue == yourValue

See also qMax() and qBound().

[править]
qint64 qRound64 ( qreal value )

Rounds value to the nearest 64-bit integer. For example:

 qreal valueA = 42949672960.3;
 qreal valueB = 42949672960.7;
 
 int roundedValueA = qRound(valueA);
 \\ roundedValueA = 42949672960
 int roundedValueB = qRound(valueB);
 \\ roundedValueB = 42949672961

[править]
int qRound ( qreal value )

Rounds value to the nearest integer. For example:

 qreal valueA = 2.3;
 qreal valueB = 2.7;
 
 int roundedValueA = qRound(valueA);
 \\ roundedValueA = 2
 int roundedValueB = qRound(valueB);
 \\ roundedValueB = 3

[править]
void qToBigEndian ( T src, uchar * dest )

Writes the number src with template type T to the memory location at dest in big-endian byte order.

Note that template type T can only be an integer data type (signed or unsigned).

There are no data alignment constraints for dest.

This function was introduced in Qt 4.3.

See also qFromBigEndian(), qFromLittleEndian(), and qToLittleEndian().

[править]
T qToBigEndian ( T src )

This is an overloaded member function, provided for convenience.

Converts src from host byte order and returns the number in big-endian byte order representation of that number. On CPU architectures where the host byte order is little-endian (such as x86) this will return src with the byte order swapped; otherwise it will return src unmodified.

This function was introduced in Qt 4.3.

[править]
void qToLittleEndian ( T src, uchar * dest )

Writes the number src with template type T to the memory location at dest in little-endian byte order.

Note that template type T can only be an integer data type (signed or unsigned).

There are no data alignment constraints for dest.

This function was introduced in Qt 4.3.

See also qFromBigEndian(), qFromLittleEndian(), and qToBigEndian().

[править]
T qToLittleEndian ( T src )

This is an overloaded member function, provided for convenience.

Converts src from host byte order and returns the number in little-endian byte order representation of that number. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will return src with the byte order swapped; otherwise it will return src unmodified.

This function was introduced in Qt 4.3.

[править]
const char * qVersion ()

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.

[править]
void qWarning ( 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.

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.

Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.

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

[править]
int qrand ()

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

[править]
void qsrand ( 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().

If no seed value is provided, qrand() is automatically seeded with a value of 1.

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

[править]
void qt_set_sequence_auto_mnemonic ( 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.

See also QShortcut.


[править] Macro Documentation

[править]
QT_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.

[править]
const char * QT_TRANSLATE_NOOP ( const char * context, const char * 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. For 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]);
 }

The macro expands to sourceText.

See also QT_TR_NOOP() and Internationalization with Qt.

[править]
const char * QT_TR_NOOP ( const char * sourceText )

Marks the string literal sourceText for dynamic translation in the current context (class), i.e the stored sourceText will not be altered. For 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 expands to sourceText.

See also QT_TRANSLATE_NOOP() and Internationalization with Qt.

[править]
QT_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. For 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().

[править]
QT_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.

[править]
void Q_ASSERT ( bool 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:

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

[править]
void Q_ASSERT_X ( bool test, const char * where, const char * 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:

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

[править]
Q_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.

 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
 ...
 #endif

See also Q_BYTE_ORDER and Q_LITTLE_ENDIAN.

[править]
Q_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.

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

[править]
Q_CC_BOR

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

[править]
Q_CC_CDS

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

[править]
Q_CC_COMEAU

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

[править]
Q_CC_DEC

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

[править]
Q_CC_EDG

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

[править]
Q_CC_GHS

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

[править]
Q_CC_GNU

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

[править]
Q_CC_HIGHC

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

[править]
Q_CC_HPACC

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

[править]
Q_CC_INTEL

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

[править]
Q_CC_KAI

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

[править]
Q_CC_MIPS

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

[править]
Q_CC_MSVC

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

[править]
Q_CC_MWERKS

Defined if the application is compiled using Metrowerks CodeWarrior.

[править]
Q_CC_OC

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

[править]
Q_CC_PGI

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

[править]
Q_CC_SUN

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

[править]
Q_CC_SYM

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

[править]
Q_CC_USLC

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

[править]
Q_CC_WAT

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

[править]
void Q_CHECK_PTR ( void * 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:

 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.

[править]
Q_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:

 struct Point2D
 {
     int x;
     int y;
 };
 
 Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);

Example of a movable type:

 class Point2D
 {
 public:
     Point2D() { data = new int[2]; }
     Point2D(const Point2D &amp;other) { ... }
     ~Point2D() { delete[] data; }
 
     Point2D &amp;operator=(const Point2D &amp;other) { ... }
 
     int x() const { return data[0]; }
     int y() const { return data[1]; }
 
 private:
     int *data;
 };
 
 Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE);

[править]
Q_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().

[править]
Q_FOREVER

Same as forever.

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

See also foreach().

[править]
const char * Q_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:

 template<typename TInputType>
 const TInputType &amp;myMin(const TInputType &amp;value1, const TInputType &amp;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.

[править]
qint64 Q_INT64_C ( literal )

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

 qint64 value = Q_INT64_C(932838457459459);

See also qint64 and Q_UINT64_C().

[править]
Q_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.

 #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
 ...
 #endif

See also Q_BYTE_ORDER and Q_BIG_ENDIAN.

[править]
Q_OS_AIX

Defined on AIX.

[править]
Q_OS_BSD4

Defined on Any BSD 4.4 system.

[править]
Q_OS_BSDI

Defined on BSD/OS.

[править]
Q_OS_CYGWIN

Defined on Cygwin.

[править]
Q_OS_DARWIN

Defined on Darwin OS (synonym for Q_OS_MAC).

[править]
Q_OS_DGUX

Defined on DG/UX.

[править]
Q_OS_DYNIX

Defined on DYNIX/ptx.

[править]
Q_OS_FREEBSD

Defined on FreeBSD.

[править]
Q_OS_HPUX

Defined on HP-UX.

[править]
Q_OS_HURD

Defined on GNU Hurd.

[править]
Q_OS_IRIX

Defined on SGI Irix.

[править]
Q_OS_LINUX

Defined on Linux.

[править]
Q_OS_LYNX

Defined on LynxOS.

[править]
Q_OS_MSDOS

Defined on MS-DOS and Windows.

[править]
Q_OS_NETBSD

Defined on NetBSD.

[править]
Q_OS_OS2

Defined on OS/2.

[править]
Q_OS_OPENBSD

Defined on OpenBSD.

[править]
Q_OS_OS2EMX

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

[править]
Q_OS_OSF

Defined on HP Tru64 UNIX.

[править]
Q_OS_QNX6

Defined on QNX RTP 6.1.

[править]
Q_OS_QNX

Defined on QNX.

[править]
Q_OS_RELIANT

Defined on Reliant UNIX.

[править]
Q_OS_SCO

Defined on SCO OpenServer 5.

[править]
Q_OS_SOLARIS

Defined on Sun Solaris.

[править]
Q_OS_ULTRIX

Defined on DEC Ultrix.

[править]
Q_OS_UNIX

Defined on Any UNIX BSD/SYSV system.

[править]
Q_OS_UNIXWARE

Defined on UnixWare 7, Open UNIX 8.

[править]
Q_OS_WIN32

Defined on all supported versions of Windows.

[править]
quint64 Q_UINT64_C ( literal )

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

 quint64 value = Q_UINT64_C(932838457459459);

See also quint64 and Q_INT64_C().

[править]
Q_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.

[править]
Q_WS_X11

Defined on X11.

See also Q_WS_MAC, Q_WS_WIN, and Q_WS_QWS.

[править]
Q_WS_MAC

Defined on Mac OS X.

See also Q_WS_WIN, Q_WS_X11, and Q_WS_QWS.

[править]
Q_WS_QWS

Defined on Qtopia Core.

See also Q_WS_MAC, Q_WS_WIN, and Q_WS_X11.

[править]
Q_WS_WIN

Defined on Windows.

See also Q_WS_MAC, Q_WS_X11, and Q_WS_QWS.

[править]
foreach ( 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:

 CONFIG += no_keywords

See also Q_FOREACH().

[править]
forever

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.

[править]
const char * qPrintable ( const QString & str )

Returns str as a const char *. This is equivalent to str.toLocal8Bit().constData().

Example:

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

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


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2