<QtGlobal> - Глобальные объявления QtЗаголовочный файл <QtGlobal> включает в себя основные глобальные объявления. Он включает в себя большинство других заголовочных файлов Qt. Далее... Типы
Функции
Макросы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. Типы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 *). Функции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. Пример: 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. Пример: 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_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: 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. Документация типовtypedef qint8Typedef for signed char. This type is guaranteed to be 8-bit on all platforms supported by Qt. typedef qint16Typedef for signed short. This type is guaranteed to be 16-bit on all platforms supported by Qt. typedef qint32Typedef for signed int. This type is guaranteed to be 32-bit on all platforms supported by Qt. typedef qint64Typedef 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); Смотрите также Q_INT64_C(), quint64 и qlonglong. typedef qlonglongTypedef for long long int (__int64 on Windows). This is the same as qint64. Смотрите также qulonglong и qint64. typedef quint8Typedef for unsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt. typedef quint16Typedef for unsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt. typedef quint32Typedef for unsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt. typedef quint64Typedef 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); Смотрите также Q_UINT64_C(), qint64 и qulonglong. typedef qulonglongTypedef for unsigned long long int (unsigned __int64 on Windows). This is the same as quint64. Смотрите также quint64 и qlonglong. Описание функций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. To access to this function, use an extern declaration: extern void qt_set_sequence_auto_mnemonic(bool b); Смотрите также QShortcut. Описание макросовQT_POINTER_SIZEExpands 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. QT_REQUIRE_VERSION ( int argc, char ** argv, const char * 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"). Пример: #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(); } QT_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. Пример: static { const char *source; const char *comment; } greeting_strings[] = { QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello", "A really friendly hello"), QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye", "A really friendly goodbye") }; QString FriendlyConversation::greeting(int type) { return tr(greeting_strings[type].source, greeting_strings[type].comment); } QString global_greeting(int type) { return qApp->translate("FriendlyConversation", greeting_strings[type].source, greeting_strings[type].comment); } Эта функция была введена в Qt 4.4. Смотрите также QT_TR_NOOP(), QT_TRANSLATE_NOOP() и Интернационализация с Qt. QT_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. Пример: 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]); } Смотрите также QT_TR_NOOP(), QT_TRANSLATE_NOOP3() и Интернационализация с Qt. QT_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. Пример: // A Symbian leaving function is being called within a Qt function. // Any leave must be converted to an exception CAknTitlePane* titlePane = S60->titlePane(); if (titlePane) { TPtrC captionPtr(qt_QString2TPtrC(caption)); QT_TRAP_THROWING(titlePane->SetTextL(captionPtr)); } Смотрите также QT_TRYCATCH_ERROR() и QT_TRYCATCH_LEAVING(). QT_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. Пример: static const char * const ids[] = { //% "This is the first text." QT_TRID_NOOP("qtn_1st_text"), //% "This is the second text." QT_TRID_NOOP("qtn_2nd_text"), 0 }; void TheClass::addLabels() { for (int i = 0; ids[i]; ++i) new QLabel(qtTrId(ids[i]), this); } Эта функция была введена в Qt 4.6. See also qtTrId() and Internationalization with Qt. QT_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. Пример: // An exception might be thrown in this Symbian TInt error returning function. // It is caught and translated to an error code TInt QServerApp::Connect(const QString &serverName) { TPtrC name; TInt err; QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName))); if (err != KErrNone) return err; return iServer.Connect(name); } } Смотрите также QT_TRYCATCH_LEAVING() и QT_TRAP_THROWING(). QT_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. Пример: // This active object signals Qt code // Exceptions from the Qt code must be converted to Symbian OS leaves for the active scheduler void QWakeUpActiveObject::RunL() { iStatus = KRequestPending; SetActive(); QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled()); } Смотрите также QT_TRAP_THROWING() и QT_TRYCATCH_ERROR(). QT_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. Пример: QString FriendlyConversation::greeting(int type) { static const char *greeting_strings[] = { QT_TR_NOOP("Hello"), QT_TR_NOOP("Goodbye") }; return tr(greeting_strings[type]); } The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate that the source string is encoded in UTF-8. Corresponding variants exist in the QT_TRANSLATE_NOOP() family of macros, too. 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. QT_VERSIONThis 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. Пример: #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_CHECKTurns 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. Смотрите также QT_VERSION. QT_VERSION_STRThis 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. Пример: // Файл: 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. Пример: // Файл: 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_ENDIANThis 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 Смотрите также Q_BYTE_ORDER и Q_LITTLE_ENDIAN. Q_BYTE_ORDERThis 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 или #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN ... #endif Смотрите также Q_BIG_ENDIAN и Q_LITTLE_ENDIAN. Q_CC_BORDefined if the application is compiled using Borland/Turbo C++. Q_CC_CDSDefined if the application is compiled using Reliant C++. Q_CC_COMEAUDefined if the application is compiled using Comeau C++. Q_CC_DECDefined if the application is compiled using DEC C++. Q_CC_EDGDefined if the application is compiled using Edison Design Group C++. Q_CC_GHSDefined if the application is compiled using Green Hills Optimizing C++ Compilers. Q_CC_GNUDefined if the application is compiled using GNU C++. Q_CC_HIGHCDefined if the application is compiled using MetaWare High C/C++. Q_CC_HPACCDefined if the application is compiled using HP aC++. Q_CC_INTELDefined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows. Q_CC_KAIDefined if the application is compiled using KAI C++. Q_CC_MIPSDefined if the application is compiled using MIPSpro C++. Q_CC_MSVCDefined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows. Q_CC_MWERKSDefined if the application is compiled using Metrowerks CodeWarrior. Q_CC_OCDefined if the application is compiled using CenterLine C++. Q_CC_PGIDefined if the application is compiled using Portland Group C++. Q_CC_SUNDefined if the application is compiled using Forte Developer, or Sun Studio C++. Q_CC_SYMDefined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++). Q_CC_USLCDefined if the application is compiled using SCO OUDK and UDK. Q_CC_WATDefined 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. Пример: int *a; Q_CHECK_PTR(a = new int[80]); // НЕПРАВИЛЬНО! a = new (nothrow) int[80]; // Правильно 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:
Example of a "primitive" type: struct Point2D { int x; int y; }; Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE); Пример перемещаемого типа: class Point2D { public: Point2D() { data = new int[2]; } Point2D(const Point2D &other) { ... } ~Point2D() { delete[] data; } Point2D &operator=(const Point2D &other) { ... } int x() const { return data[0]; } int y() const { return data[1]; } private: int *data; }; Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE); Q_DECL_EXPORTThis macro marks a symbol for shared library export (see Creating Shared Libraries). Смотрите также Q_DECL_IMPORT. Q_DECL_IMPORTThis macro declares a symbol to be an import from a shared library (see Creating Shared Libraries). Смотрите также Q_DECL_EXPORT. 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. Смотрите также foreach(). Q_FOREVERSame as forever. This macro is available even when no_keywords is specified using the .pro file's CONFIG variable. Смотрите также 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 &myMin(const TInputType &value1, const TInputType &value2) { qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; if(value1 < value2) return value1; else return value2; } when instantiated with the integer type, will with the GCC compiler produce: const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4 If this macro is used outside a function, the behavior is undefined. qint64 Q_INT64_C ( literal )Wraps the signed 64-bit integer literal in a platform-independent way. Пример: qint64 value = Q_INT64_C(932838457459459); Смотрите также qint64 и Q_UINT64_C(). Q_LIKELY ( expr )Hints to the compiler that the enclosed condition, expr, is likely to evaluate to true. Use of this macro can help the compiler to optimize the code. Пример: // the condition inside the "if" will be successful most of the times for (int i = 1; i <= 365; i++) { if (Q_LIKELY(isWorkingDay(i))) { ... } ... } Эта функция была введена в Qt 4.8. Смотрите также Q_UNLIKELY(). Q_LITTLE_ENDIANThis 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 Смотрите также Q_BYTE_ORDER и Q_BIG_ENDIAN. Q_OS_AIXDefined on AIX. Q_OS_BSD4Defined on Any BSD 4.4 system. Q_OS_BSDIDefined on BSD/OS. Q_OS_CYGWINDefined on Cygwin. Q_OS_DARWINDefined on Darwin OS (synonym for Q_OS_MAC). Q_OS_DGUXDefined on DG/UX. Q_OS_DYNIXDefined on DYNIX/ptx. Q_OS_FREEBSDDefined on FreeBSD. Q_OS_HPUXDefined on HP-UX. Q_OS_HURDDefined on GNU Hurd. Q_OS_IRIXDefined on SGI Irix. Q_OS_LINUXDefined on Linux. Q_OS_LYNXDefined on LynxOS. Q_OS_MACDefined on MAC OS (synonym for Darwin). Q_OS_MSDOSDefined on MS-DOS and Windows. Q_OS_NETBSDDefined on NetBSD. Q_OS_OS2Defined on OS/2. Q_OS_OPENBSDDefined on OpenBSD. Q_OS_OS2EMXDefined on XFree86 on OS/2 (not PM). Q_OS_OSFDefined on HP Tru64 UNIX. Q_OS_QNXDefined on QNX Neutrino. Q_OS_RELIANTDefined on Reliant UNIX. Q_OS_SCODefined on SCO OpenServer 5. Q_OS_SOLARISDefined on Sun Solaris. Q_OS_SYMBIANDefined on Symbian. Q_OS_ULTRIXDefined on DEC Ultrix. Q_OS_UNIXDefined on Any UNIX BSD/SYSV system. Q_OS_UNIXWAREDefined on UnixWare 7, Open UNIX 8. Q_OS_WIN32Defined on all supported versions of Windows. Q_OS_WINCEDefined on Windows CE. quint64 Q_UINT64_C ( literal )Wraps the unsigned 64-bit integer literal in a platform-independent way. Пример: quint64 value = Q_UINT64_C(932838457459459); Смотрите также quint64 и Q_INT64_C(). Q_UNLIKELY ( expr )Hints to the compiler that the enclosed condition, expr, is likely to evaluate to false. Use of this macro can help the compiler to optimize the code. Пример: bool readConfiguration(const QFile &file) { // We expect to be asked to read an existing file if (Q_UNLIKELY(!file.exists())) { qWarning() << "File not found"; return false; } ... return true; } Эта функция была введена в Qt 4.8. Смотрите также Q_LIKELY(). 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_S60Defined on S60 with the Avkon UI framework. Смотрите также Q_WS_MAC, Q_WS_WIN, Q_WS_X11 и Q_WS_QWS. Q_WS_X11Defined on X11. Смотрите также Q_WS_MAC, Q_WS_WIN, Q_WS_QWS, Q_WS_QPA и Q_WS_S60. Q_WS_MACDefined on Mac OS X. Смотрите также Q_WS_WIN, Q_WS_X11, Q_WS_QWS, Q_WS_QPA и Q_WS_S60. Q_WS_QPADefined on Qt for Embedded Linux, Lite version. Смотрите также Q_WS_MAC, Q_WS_WIN, Q_WS_X11, Q_WS_QWS и Q_WS_S60. Q_WS_QWSDefined on Qt for Embedded Linux. Смотрите также Q_WS_MAC, Q_WS_WIN, Q_WS_X11, Q_WS_QPA и Q_WS_S60. Q_WS_WINDefined on Windows. Смотрите также Q_WS_MAC, Q_WS_X11, Q_WS_QWS, Q_WS_QPA и Q_WS_S60. 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 Смотрите также Q_FOREACH(). foreverThis macro is provided for convenience for writing infinite loops. Пример: 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 Смотрите также Q_FOREVER. const char * qPrintable ( const QString & 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. Пример: qWarning("%s: %s", qPrintable(key), qPrintable(value)); See also qDebug(), qWarning(), qCritical(), and qFatal(). |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |