IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

<QtGlobal> - Global Qt Declarations

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

<QtGlobal> - Global Qt Declarations▲

  • Header: QtGlobal

  • Group: <QtGlobal> is part of funclists

Detailed Description▲

The global declarations include https://, https:// and https://.

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 https:// which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. The header file also declares the https:// type definition for long long int (__int64 on Windows).

Several convenience type definitions are declared: https:// for double or float, https:// for unsigned char, https:// for unsigned int, https:// for unsigned long and https:// for unsigned short.

Finally, the https:// definition identifies the various messages that can be generated and sent to a Qt message handler; https:// is a type definition for a pointer to a function with the signature void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *). https:// class contains the line, file, and function the message was logged at. This information is created by the QMessageLogger class.

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:

 
Sélectionnez
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: https://(), https://(), https://(), https://(), and https://(). These functions call the message handler with the given message.

Example:

 
Sélectionnez
if (!driver()-&gt;isOpen() || driver()-&gt;isOpenError()) {
    qWarning("QSqlQuery::exec: database not open");
    return false;
}

The remaining functions are https://() and qRound64(), which both accept a double or float value as their argument returning the value rounded up to the nearest integer and 64-bit integer respectively, the qInstallMessageHandler() function which installs the given https://, 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 https:// 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, https:// which is defined for the Unix-based systems.

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 https://(), https://(), and https://() macros provide the possibility of marking strings for delayed translation. https://(), https://(), and https://() are numerator dependent variants of these. The https://() and https://() enables warning messages of various level of refinement. The https://() and https://() macros implement Qt's foreach loop.

The https://() and https://() macros wrap signed and unsigned 64-bit integer literals in a platform-independent way. The https://() 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 https://() and https://() macros represent an easy way of printing text.

The https:// macro expands to the size of a pointer in bytes.

The macros https:// and https:// expand to a numeric value or a string, respectively, that specifies the version of Qt that the application is compiled against.

See Also▲

See also https://, QSysInfo

Type Documentation▲

 

QFunctionPointer▲

This is a typedef for void (*)(), a pointer to a function that takes no arguments and returns void.

[since 5.0] QtMessageHandler▲

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

 
Sélectionnez
void myMessageHandler(QtMsgType, const QMessageLogContext &amp;, const QString &amp;);

This typedef was introduced in Qt 5.0.

See Also▲

See also https://, qInstallMessageHandler()

enum QtMsgType▲

This enum describes the messages that can be sent to a message handler (https://). 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 https://() function.

QtInfoMsg

4

A message generated by the https://() function.

QtWarningMsg

1

A message generated by the https://() function.

QtCriticalMsg

2

A message generated by the https://() function.

QtFatalMsg

3

A message generated by the https://() function.

QtSystemMsg

QtCriticalMsg

 

QtInfoMsg was added in Qt 5.5.

See Also▲

See also https://, qInstallMessageHandler()

qint8▲

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

qint16▲

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

qint32▲

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

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 https://() macro:

 
Sélectionnez
qint64 value = Q_INT64_C(932838457459459);
See Also▲

See also https://(), https://, https://

qintptr▲

Integral type for representing pointers in a signed integer (useful for hashing, etc.).

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, qintptr is a typedef for qint32; on a system with 64-bit pointers, qintptr is a typedef for qint64.

Note that qintptr is signed. Use quintptr for unsigned values.

See Also▲

See also https://, https://, https://

qlonglong▲

Typedef for long long int (__int64 on Windows). This is the same as https://.

See Also▲

See also https://, https://

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▲

See also https://, https://, https://

qreal▲

Typedef for double unless Qt is configured with the -qreal float option.

[alias, since 5.10] qsizetype▲

Integral type providing Posix' ssize_t for all platforms.

This type is guaranteed to be the same size as a size_t on all platforms supported by Qt.

Note that qsizetype is signed. Use size_t for unsigned values.

This typedef was introduced in Qt 5.10.

See Also▲

See also https://

quint8▲

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

quint16▲

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

quint32▲

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

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 https://() macro:

 
Sélectionnez
quint64 value = Q_UINT64_C(932838457459459);
See Also▲

See also https://(), https://, https://

quintptr▲

Integral type for representing pointers in an unsigned integer (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▲

See also https://, https://, https://

qulonglong▲

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

See Also▲

See also https://, https://

uchar▲

Convenience typedef for unsigned char.

uint▲

Convenience typedef for unsigned int.

ulong▲

Convenience typedef for unsigned long.

ushort▲

Convenience typedef for unsigned short.

Function Documentation▲

 

[since 5.7] int &qAsConst(T &t)▲

Returns t cast to const T.

This function is a Qt implementation of C++17's std::as_const(), a cast function like std::move(). But while std::move() turns lvalues into rvalues, this function turns non-const lvalues into const lvalues. Like std::as_const(), it doesn't work on rvalues, because it cannot be efficiently implemented for rvalues without leaving dangling references.

Its main use in Qt is to prevent implicitly-shared Qt containers from detaching:

 
Sélectionnez
    QString s = ...;
    for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
        process(ch);
    for (QChar ch : qAsConst(s)) // ok, no detach attempt
        process(ch);

Of course, in this case, you could (and probably should) have declared s as const in the first place:

 
Sélectionnez
    const QString s = ...;
    for (QChar ch : s) // ok, no detach attempt on const objects
        process(ch);

but often that is not easily possible.

It is important to note that qAsConst() does not copy its argument, it just performs a const_cast<const T&>(t). This is also the reason why it is designed to fail for rvalues: The returned reference would go stale too soon. So while this works (but detaches the returned object):

 
Sélectionnez
    for (QChar ch : funcReturningQString())
        process(ch); // OK, the returned object is kept alive for the loop's duration

this would not:

 
Sélectionnez
    for (QChar ch : qAsConst(funcReturningQString()))
        process(ch); // ERROR: ch is copied from deleted memory

To prevent this construct from compiling (and failing at runtime), qAsConst() has a second, deleted, overload which binds to rvalues.

This function was introduced in Qt 5.7.

[since 5.7] auto qConstOverload(T memberFunctionPointer)▲

Returns the memberFunctionPointer pointer to a constant member function:

 
Sélectionnez
    struct Foo {
        void overloadedFunction(int, const QString &amp;);
        void overloadedFunction(int, const QString &amp;) const;
    };
    ... qConstOverload&lt;int, const QString &amp;&gt;(&amp;Foo::overloadedFunction)
    ... qNonConstOverload&lt;int, const QString &amp;&gt;(&amp;Foo::overloadedFunction)

This function was introduced in Qt 5.7.

See Also▲

See also https://, https://, https://

[since 4.4] int qFuzzyCompare(double p1, double p2)▲

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, nor does comparing values where one of the values is NaN or infinity. If one of the values is always 0.0, use https:// instead. If one of the values is likely to be 0.0, one solution is to add 1.0 to both values.

 
Sélectionnez
// Instead of comparing with 0.0
qFuzzyCompare(0.0, 1.0e-200); // This will return false
// Compare adding 1 to both values will fix the problem
qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true

The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.

This function is https://.

This function was introduced in Qt 4.4.

[since 4.4] int qFuzzyCompare(float p1, float p2)▲

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.

This function is https://.

This function was introduced in Qt 4.4.

[since 4.4] int qFuzzyIsNull(double d)▲

Returns true if the absolute value of d is within 0.000000000001 of 0.0.

This function is https://.

This function was introduced in Qt 4.4.

[since 4.4] int qFuzzyIsNull(float f)▲

Returns true if the absolute value of f is within 0.00001f of 0.0.

This function is https://.

This function was introduced in Qt 4.4.

double qInf()▲

Returns the bit pattern for an infinite number as a double.

bool qIsFinite(double d)▲

Returns true if the double d is a finite number.

bool qIsFinite(float f)▲

Returns true if the float f is a finite number.

bool qIsInf(double d)▲

Returns true if the double d is equivalent to infinity.

bool qIsInf(float f)▲

Returns true if the float f is equivalent to infinity.

bool qIsNaN(double d)▲

Returns true if the double d is not a number (NaN).

bool qIsNaN(float f)▲

Returns true if the float f is not a number (NaN).

[since 5.7] auto qNonConstOverload(T memberFunctionPointer)▲

Returns the memberFunctionPointer pointer to a non-constant member function:

 
Sélectionnez
    struct Foo {
        void overloadedFunction(int, const QString &amp;);
        void overloadedFunction(int, const QString &amp;) const;
    };
    ... qConstOverload&lt;int, const QString &amp;&gt;(&amp;Foo::overloadedFunction)
    ... qNonConstOverload&lt;int, const QString &amp;&gt;(&amp;Foo::overloadedFunction)

This function was introduced in Qt 5.7.

See Also▲

See also https://, qNonConstOverload, https://

[since 5.7] auto qOverload(T functionPointer)▲

Returns a pointer to an overloaded function. The template parameter is the list of the argument types of the function. functionPointer is the pointer to the (member) function:

 
Sélectionnez
    struct Foo {
        void overloadedFunction();
        void overloadedFunction(int, const QString &amp;);
    };
    ... qOverload&lt;&gt;(&amp;Foo::overloadedFunction)
    ... qOverload&lt;int, const QString &amp;&gt;(&amp;Foo::overloadedFunction)

If a member function is also const-overloaded https:// and https:// need to be used.

qOverload() requires C++14 enabled. In C++11-only code, the helper classes QOverload, QConstOverload, and QNonConstOverload can be used directly:

 
Sélectionnez
    ... QOverload&lt;&gt;::of(&amp;Foo::overloadedFunction)
    ... QOverload&lt;int, const QString &amp;&gt;::of(&amp;Foo::overloadedFunction)

Qt detects the necessary C++14 compiler support by way of the feature test recommendations from https://.

This function was introduced in Qt 5.7.

See Also▲

See also https://(), https://(), https://

double qQNaN()▲

Returns the bit pattern of a quiet NaN as a double.

int qRound(double d)▲

Rounds d to the nearest integer.

Rounds half up (e.g. 0.5 -> 1, -0.5 -> 0).

Example:

 
Sélectionnez
double valueA = 2.3;
double valueB = 2.7;

int roundedValueA = qRound(valueA);
// roundedValueA = 2
int roundedValueB = qRound(valueB);
// roundedValueB = 3

int qRound(float d)▲

Rounds d to the nearest integer.

Rounds half up (e.g. 0.5f -> 1, -0.5f -> 0).

Example:

 
Sélectionnez
float valueA = 2.3;
float valueB = 2.7;

int roundedValueA = qRound(valueA);
// roundedValueA = 2
int roundedValueB = qRound(valueB);
// roundedValueB = 3

double qSNaN()▲

Returns the bit pattern of a signalling NaN as a double.

T *q_check_ptr(T *p)▲

Uses https:// on p, then returns p.

This can be used as an inline version of https://.

[constexpr] int qputenv(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.

Calling qputenv with an empty value removes the environment variable on Windows, and makes it set (but empty) on Unix. Prefer using https://() for fully portable behavior.

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▲

See also qgetenv(), qEnvironmentVariable()

[constexpr, since 5.1] int qunsetenv(const char *varName)▲

This function deletes the variable varName from the environment.

Returns true on success.

This function was introduced in Qt 5.1.

See Also▲

See also https://(), qgetenv(), qEnvironmentVariable()

Macro Documentation▲

 

QT_DEPRECATED_WARNINGS▲

Since Qt 5.13, this macro has no effect. In Qt 5.12 and before, if this macro is defined, the compiler will generate warnings if any API declared as deprecated by Qt is used.

See Also▲

See also https://, https://

QT_DISABLE_DEPRECATED_BEFORE▲

This macro can be defined in the project file to disable functions deprecated in a specified version of Qt or any earlier version. The default version number is 5.0, meaning that functions deprecated in or before Qt 5.0 will not be included.

For instance, when using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to disable functions deprecated in Qt 5.1 and earlier. In any release, set QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable all functions, including the ones deprecated in Qt 5.0.

See Also▲

See also https://

[since 5.13] QT_NO_DEPRECATED_WARNINGS▲

This macro can be used to suppress deprecation warnings that would otherwise be generated when using deprecated APIs.

This macro was introduced in Qt 5.13.

See Also▲

See also https://

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.

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

Example:

 
Sélectionnez
#include &lt;QApplication&gt;
#include &lt;QMessageBox&gt;

int main(int argc, char *argv[])
{
    QT_REQUIRE_VERSION(argc, argv, "4.0.2")

    QApplication app(argc, argv);
    ...
    return app.exec();
}

[since 4.4] QT_TRANSLATE_NOOP3(context, sourceText, disambiguation)▲

Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context with the given disambiguation. The context is typically a class and also needs to be specified as a string literal. The string literal disambiguation should be a short semantic tag to tell apart otherwise identical strings.

The macro tells lupdate to collect the string, and expands to an anonymous struct of the two string literals passed as sourceText and disambiguation.

Example:

 
Sélectionnez
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-&gt;translate("FriendlyConversation",
                           greeting_strings[type].source,
                           greeting_strings[type].comment);
}

This macro was introduced in Qt 4.4.

See Also▲

See also https://(), https://(), https://

QT_TRANSLATE_NOOP(context, sourceText)▲

Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context. The context is typically a class name and also needs to be specified as a string literal.

The macro tells lupdate to collect the string, and expands to sourceText itself.

Example:

 
Sélectionnez
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-&gt;translate("FriendlyConversation",
                           greeting_strings[type]);
}
See Also▲

See also https://(), https://(), https://

[since 5.12] QT_TRANSLATE_N_NOOP3(context, sourceText, comment)▲

Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the given context with the given comment. The context is typically a class and also needs to be specified as a string literal. The string literal comment should be a short semantic tag to tell apart otherwise identical strings.

The macro tells lupdate to collect the string, and expands to an anonymous struct of the two string literals passed as sourceText and comment.

Example:

 
Sélectionnez
static { const char * const source; const char * const comment; } status_strings[] = {
    QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
                         "A login message status"),
    QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
                         "A new message query status")
};

QString FriendlyConversation::greeting(int type, int count)
{
    return tr(status_strings[type].source,
              status_strings[type].comment, count);
}

QString global_greeting(int type, int count)
{
    return qApp-&gt;translate("Message Status",
                           status_strings[type].source,
                           status_strings[type].comment,
                           count);
}

This macro was introduced in Qt 5.12.

See Also▲

See also https://(), https://(), https://(), https://

[since 5.12] QT_TRANSLATE_N_NOOP(context, sourceText)▲

Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the given context. The context is typically a class name and also needs to be specified as a string literal.

The macro tells lupdate to collect the string, and expands to sourceText itself.

Example:

 
Sélectionnez
static const char * const greeting_strings[] = {
    QT_TRANSLATE_N_NOOP("Welcome Msg", "Hello, you have %n message(s)"),
    QT_TRANSLATE_N_NOOP("Welcome Msg", "Hi, you have %n message(s)")
};

QString global_greeting(int type, int msgcnt)
{
    return translate("Welcome Msg", greeting_strings[type], nullptr, msgcnt);
}

This macro was introduced in Qt 5.12.

See Also▲

See also https://(), https://(), https://

[since 4.6] 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.

Example:

 
Sélectionnez
static const char * const ids[] = {
    //% "This is the first text."
    QT_TRID_NOOP("qtn_1st_text"),
    //% "This is the second text."
    QT_TRID_NOOP("qtn_2nd_text"),
    0
};

void TheClass::addLabels()
{
    for (int i = 0; ids[i]; ++i)
        new QLabel(qtTrId(ids[i]), this);
}

This macro was introduced in Qt 4.6.

See Also▲

See also https://, Internationalization with Qt

QT_TR_NOOP(sourceText)▲

Marks the UTF-8 encoded string literal sourceText for delayed translation in the current context (class).

The macro tells lupdate to collect the string, and expands to sourceText itself.

Example:

 
Sélectionnez
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 and obsolete; this applies to all other _UTF8 macros as well.

See Also▲

See also https://(), https://

[since 5.12] QT_TR_N_NOOP(sourceText)▲

Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the current context (class).

The macro tells lupdate to collect the string, and expands to sourceText itself.

The macro expands to sourceText.

Example:

 
Sélectionnez
static const char * const StatusClass::status_strings[] = {
    QT_TR_N_NOOP("There are %n new message(s)"),
    QT_TR_N_NOOP("There are %n total message(s)")
};

QString StatusClass::status(int type, int count)
{
    return tr(status_strings[type], nullptr, count);
}

This macro was introduced in Qt 5.12.

See Also▲

See also https://, https://

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.

Example:

 
Sélectionnez
#if QT_VERSION &gt;= 0x040100
    QIcon icon = style()-&gt;standardIcon(QStyle::SP_TrashIcon);
#else
    QPixmap pixmap = style()-&gt;standardPixmap(QStyle::SP_TrashIcon);
    QIcon icon(pixmap);
#endif
See Also▲

See also https://, qVersion()

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

Example:

 
Sélectionnez
#include &lt;QtGlobal&gt;

#if (QT_VERSION &gt;= QT_VERSION_CHECK(5, 0, 0))
#include &lt;QtWidgets&gt;
#else
#include &lt;QtGui&gt;
#endif
See Also▲

See also https://

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▲

See also https://, 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:

 
Sélectionnez
// File: div.cpp

#include &lt;QtGlobal&gt;

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 https://() function:

 
Sélectionnez
ASSERT: "b != 0" in file div.cpp, line 7
See Also▲

See also https://(), https://(), https://

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:

 
Sélectionnez
// File: div.cpp

#include &lt;QtGlobal&gt;

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 https://() function:

 
Sélectionnez
ASSERT failure in divide: "division by zero", file div.cpp, line 7
See Also▲

See also https://(), https://(), https://

[since 5.0] void Q_ASSUME(bool expr)▲

Causes the compiler to assume that expr is true. This macro is useful for improving code generation, by providing the compiler with hints about conditions that it would not otherwise know about. However, there is no guarantee that the compiler will actually use those hints.

This macro could be considered a "lighter" version of https://(). While https:// will abort the program's execution if the condition is false, Q_ASSUME will tell the compiler not to generate code for those conditions. Therefore, it is important that the assumptions always hold, otherwise undefined behaviour may occur.

If expr is a constantly false condition, Q_ASSUME will tell the compiler that the current code execution cannot be reached. That is, Q_ASSUME(false) is equivalent to https://().

In debug builds the condition is enforced by an assert to facilitate debugging.

https://() tells the compiler that the expression is likely, but not the only possibility. Q_ASSUME tells the compiler that it is the only possibility.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://()

Q_BIG_ENDIAN▲

This macro represents a value you can compare to the macro https:// 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.

 
Sélectionnez
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
...
#endif
See Also▲

See also https://, https://

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 https:// or https://. 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.

 
Sélectionnez
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
...
#endif

or

#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
...
#endif
See Also▲

See also https://, https://

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_CLANG▲

Defined if the application is compiled using Clang.

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_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 message containing the source code's file name and line number, saying that the program ran out of memory and aborts program execution. It throws std::bad_alloc instead if exceptions are enabled.

Q_CHECK_PTR does nothing if QT_NO_DEBUG and QT_NO_EXCEPTIONS were defined during compilation. Therefore you must not use Q_CHECK_PTR to check for successful memory allocations because the check will be disabled in some cases.

Example:

 
Sélectionnez
int *a;

Q_CHECK_PTR(a = new int[80]);   // WRONG!

a = new (nothrow) int[80];      // Right
Q_CHECK_PTR(a);
See Also▲

See also https://(), https://

Q_DECLARE_TYPEINFO(Type, Flags)▲

You can use this macro to specify information about a custom type Type. With accurate type information, Qt's https:// 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, or else a type where every bit pattern is a valid object and memcpy() creates a valid independent copy of the object.

  • Q_MOVABLE_TYPE specifies that Type has a constructor and/or a destructor but can be moved in memory using memcpy(). Note: despite the name, this has nothing to do with move constructors or C++ move semantics.

  • 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:

 
Sélectionnez
struct Point2D
{
    int x;
    int y;
};

Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);

An example of a non-POD "primitive" type is QUuid: Even though QUuid has constructors (and therefore isn't POD), every bit pattern still represents a valid object, and memcpy() can be used to create a valid independent copy of a QUuid object.

Example of a movable type:

 
Sélectionnez
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);

Qt will try to detect the class of a type using std::is_trivial or std::is_trivially_copyable. Use this macro to tune the behavior. For instance many types would be candidates for Q_MOVABLE_TYPE despite not being trivially-copyable. For binary compatibility reasons, https:// optimizations are only enabled if there is an explicit Q_DECLARE_TYPEINFO even for trivially-copyable types.

Q_DECL_CONSTEXPR▲

This macro can be used to declare variable that should be constructed at compile-time, or an inline function that can be computed at compile-time.

It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing otherwise.

See Also▲

See also https://

Q_DECL_EXPORT▲

This macro marks a symbol for shared library export (see https://).

See Also▲

See also https://

[since 5.0] Q_DECL_FINAL▲

This macro can be used to declare an overriding virtual or a class as "final", with Java semantics. Further-derived classes can then no longer override this virtual function, or inherit from this class, respectively.

It expands to "final" if your compiler supports that C++11 contextual keyword, or something non-standard if your compiler supports something close enough to the C++11 semantics, or to nothing otherwise.

The macro goes at the end of the function, usually after the const, if any:

 
Sélectionnez
    // more-derived classes no longer permitted to override this:
    virtual void MyWidget::paintEvent(QPaintEvent*) final;

For classes, it goes in front of the : in the class definition, if any:

 
Sélectionnez
    class QRect final { // cannot be derived from
        // ...
    };

This macro was introduced in Qt 5.0.

See Also▲

See also https://

Q_DECL_IMPORT▲

This macro declares a symbol to be an import from a shared library (see https://).

See Also▲

See also https://

[since 5.0] Q_DECL_NOEXCEPT▲

This macro marks a function as never throwing. If the function does nevertheless throw, the behaviour is defined: std::terminate() is called.

The macro expands to C++11 noexcept, if available, or to nothing otherwise.

If you need the operator version of C++11 noexcept, use https://(x).

If you don't need C++11 noexcept semantics, e.g. because your function can't possibly throw, don't use this macro, use https:// instead.

This macro was introduced in Qt 5.0.

See Also▲

See also https://, https://()

[since 5.0] Q_DECL_NOEXCEPT_EXPR(x)▲

This macro marks a function as non-throwing if x is true. If the function does nevertheless throw, the behaviour is defined: std::terminate() is called.

The macro expands to C++11 noexcept(x), if available, or to nothing otherwise.

If you need the always-true version of C++11 noexcept, use https://.

If you don't need C++11 noexcept semantics, e.g. because your function can't possibly throw, don't use this macro, use https:// instead.

This macro was introduced in Qt 5.0.

See Also▲

See also https://, https://

[since 5.0] Q_DECL_NOTHROW▲

This macro marks a function as never throwing, under no circumstances. If the function does nevertheless throw, the behaviour is undefined.

The macro expands to either "throw()", if that has some benefit on the compiler, or to C++11 noexcept, if available, or to nothing otherwise.

If you need C++11 noexcept semantics, don't use this macro, use https:///https:// instead.

This macro was introduced in Qt 5.0.

See Also▲

See also https://, https://()

[since 5.0] Q_DECL_OVERRIDE▲

This macro can be used to declare an overriding virtual function. Use of this markup will allow the compiler to generate an error if the overriding virtual function does not in fact override anything.

It expands to "override" if your compiler supports that C++11 contextual keyword, or to nothing otherwise.

The macro goes at the end of the function, usually after the const, if any:

 
Sélectionnez
    // generate error if this doesn't actually override anything:
    virtual void MyWidget::paintEvent(QPaintEvent*) override;

This macro was introduced in Qt 5.0.

See Also▲

See also https://

Q_DECL_RELAXED_CONSTEXPR▲

This macro can be used to declare an inline function that can be computed at compile-time according to the relaxed rules from C++14.

It expands to "constexpr" if your compiler supports C++14 relaxed constant expressions, or to nothing otherwise.

See Also▲

See also https://

[since 5.8] void Q_FALLTHROUGH▲

Can be used in switch statements at the end of case block to tell the compiler and other developers that that the lack of a break statement is intentional.

This is useful since a missing break statement is often a bug, and some compilers can be configured to emit warnings when one is not found.

This macro was introduced in Qt 5.8.

See Also▲

See also https://()

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.

Since Qt 5.7, the use of this macro is discouraged. It will be removed in a future version of Qt. Please use C++11 range-for, possibly with https://(), as needed.

See Also▲

See also https://()

Q_FOREVER▲

Same as https://.

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

See Also▲

See also https://()

[since 5.2] Q_FORWARD_DECLARE_CF_TYPE(type)▲

Forward-declares a Core Foundation type. This includes the actual type and the ref type. For example, Q_FORWARD_DECLARE_CF_TYPE(CFString) declares __CFString and CFStringRef.

This macro was introduced in Qt 5.2.

[since 5.2] Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type)▲

Forward-declares a mutable Core Foundation type. This includes the actual type and the ref type. For example, Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(CFMutableString) declares __CFMutableString and CFMutableStringRef.

This macro was introduced in Qt 5.2.

[since 5.2] Q_FORWARD_DECLARE_OBJC_CLASS(classname)▲

Forward-declares an Objective-C classname in a manner such that it can be compiled as either Objective-C or C++.

This is primarily intended for use in header files that may be included by both Objective-C and C++ source files.

This macro was introduced in Qt 5.2.

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 https://(). For example, this function:

 
Sélectionnez
template&lt;typename TInputType&gt;
const TInputType &amp;myMin(const TInputType &amp;value1, const TInputType &amp;value2)
{
    qDebug() &lt;&lt; Q_FUNC_INFO &lt;&lt; "was called with value1:" &lt;&lt; value1 &lt;&lt; "value2:" &lt;&lt; value2;

    if(value1 &lt; 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.

Example:

 
Sélectionnez
qint64 value = Q_INT64_C(932838457459459);
See Also▲

See also https://, https://()

[since 4.8] 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.

Example:

 
Sélectionnez
    // the condition inside the "if" will be successful most of the times
    for (int i = 1; i &lt;= 365; i++) {
        if (Q_LIKELY(isWorkingDay(i))) {
            ...
        }
        ...
    }

This macro was introduced in Qt 4.8.

See Also▲

See also https://()

Q_LITTLE_ENDIAN▲

This macro represents a value you can compare to the macro https:// 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.

 
Sélectionnez
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
...
#endif
See Also▲

See also https://, https://

Q_OS_AIX▲

Defined on AIX.

Q_OS_ANDROID▲

Defined on Android.

Q_OS_BSD4▲

Defined on Any BSD 4.4 system.

Q_OS_CYGWIN▲

Defined on Cygwin.

Q_OS_DARWIN▲

Defined on Darwin-based operating systems such as macOS, iOS, watchOS, and tvOS.

Q_OS_FREEBSD▲

Defined on FreeBSD.

Q_OS_HPUX▲

Defined on HP-UX.

Q_OS_HURD▲

Defined on GNU Hurd.

Q_OS_IOS▲

Defined on iOS.

Q_OS_LINUX▲

Defined on Linux.

Q_OS_LYNX▲

Defined on LynxOS.

Q_OS_MAC▲

Deprecated synonym for Q_OS_DARWIN. Do not use.

Q_OS_MACOS▲

Defined on macOS.

Q_OS_NETBSD▲

Defined on NetBSD.

Q_OS_OPENBSD▲

Defined on OpenBSD.

Q_OS_OSX▲

Deprecated synonym for Q_OS_MACOS. Do not use.

Q_OS_QNX▲

Defined on QNX Neutrino.

Q_OS_SOLARIS▲

Defined on Sun Solaris.

Q_OS_TVOS▲

Defined on tvOS.

Q_OS_UNIX▲

Defined on Any UNIX BSD/SYSV system.

Q_OS_WASM▲

Defined on Web Assembly.

Q_OS_WATCHOS▲

Defined on watchOS.

Q_OS_WIN32▲

Defined on 32-bit and 64-bit versions of Windows.

Q_OS_WIN64▲

Defined on 64-bit versions of Windows.

Q_OS_WIN▲

Defined on all supported versions of Windows. That is, if https://, https://, or https:// is defined.

Q_OS_WINDOWS▲

This is a synonym for https://.

Q_OS_WINRT▲

Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT, and Windows Phone 8.

Q_PROCESSOR_X86▲

Defined if the application is compiled for x86 processors. Qt currently supports two x86 variants: https:// and https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_S390▲

Defined if the application is compiled for S/390 processors. Qt supports one optional variant of S/390: https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_ALPHA▲

Defined if the application is compiled for Alpha processors.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_ARM▲

Defined if the application is compiled for ARM processors. Qt currently supports three optional ARM revisions: https://, https://, and https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_ARM_V5▲

Defined if the application is compiled for ARMv5 processors. The https:// macro is also defined when Q_PROCESSOR_ARM_V5 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_ARM_V6▲

Defined if the application is compiled for ARMv6 processors. The https:// and https:// macros are also defined when Q_PROCESSOR_ARM_V6 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_ARM_V7▲

Defined if the application is compiled for ARMv7 processors. The https://, https://, and https:// macros are also defined when Q_PROCESSOR_ARM_V7 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_AVR32▲

Defined if the application is compiled for AVR32 processors.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_BLACKFIN▲

Defined if the application is compiled for Blackfin processors.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_IA64▲

Defined if the application is compiled for IA-64 processors. This includes all Itanium and Itanium 2 processors.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS▲

Defined if the application is compiled for MIPS processors. Qt currently supports seven MIPS revisions: https://, https://, https://, https://, https://, https://, and https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_32▲

Defined if the application is compiled for MIPS32 processors. The https://, https://, and https:// macros are also defined when Q_PROCESSOR_MIPS_32 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_64▲

Defined if the application is compiled for MIPS64 processors. The https://, https://, https://, https://, https://, and https:// macros are also defined when Q_PROCESSOR_MIPS_64 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_I▲

Defined if the application is compiled for MIPS-I processors. The https:// macro is also defined when Q_PROCESSOR_MIPS_I is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_II▲

Defined if the application is compiled for MIPS-II processors. The https:// and https:// macros are also defined when Q_PROCESSOR_MIPS_II is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_III▲

Defined if the application is compiled for MIPS-III processors. The https://, https://, and https:// macros are also defined when Q_PROCESSOR_MIPS_III is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_IV▲

Defined if the application is compiled for MIPS-IV processors. The https://, https://, https://, and https:// macros are also defined when Q_PROCESSOR_MIPS_IV is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_MIPS_V▲

Defined if the application is compiled for MIPS-V processors. The https://, https://, https://, https://, and https:// macros are also defined when Q_PROCESSOR_MIPS_V is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_POWER▲

Defined if the application is compiled for POWER processors. Qt currently supports two Power variants: https:// and https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_POWER_32▲

Defined if the application is compiled for 32-bit Power processors. The https:// macro is also defined when Q_PROCESSOR_POWER_32 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_POWER_64▲

Defined if the application is compiled for 64-bit Power processors. The https:// macro is also defined when Q_PROCESSOR_POWER_64 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_S390_X▲

Defined if the application is compiled for S/390x processors. The https:// macro is also defined when Q_PROCESSOR_S390_X is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_SH▲

Defined if the application is compiled for SuperH processors. Qt currently supports one SuperH revision: https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_SH_4A▲

Defined if the application is compiled for SuperH 4A processors. The https:// macro is also defined when Q_PROCESSOR_SH_4A is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_SPARC▲

Defined if the application is compiled for SPARC processors. Qt currently supports one optional SPARC revision: https://.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_SPARC_V9▲

Defined if the application is compiled for SPARC V9 processors. The https:// macro is also defined when Q_PROCESSOR_SPARC_V9 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_X86_32▲

Defined if the application is compiled for 32-bit x86 processors. This includes all i386, i486, i586, and i686 processors. The https:// macro is also defined when Q_PROCESSOR_X86_32 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

Q_PROCESSOR_X86_64▲

Defined if the application is compiled for 64-bit x86 processors. This includes all AMD64, Intel 64, and other x86_64/x64 processors. The https:// macro is also defined when Q_PROCESSOR_X86_64 is defined.

See Also▲

See also QSysInfo::buildCpuArchitecture()

quint64 Q_UINT64_C(literal)▲

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

Example:

 
Sélectionnez
quint64 value = Q_UINT64_C(932838457459459);
See Also▲

See also https://, https://()

[since 4.8] 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.

Example:

 
Sélectionnez
bool readConfiguration(const QFile &amp;file)
{
    // We expect to be asked to read an existing file
    if (Q_UNLIKELY(!file.exists())) {
        qWarning() &lt;&lt; "File not found";
        return false;
    }

    ...
    return true;
}

This macro was introduced in Qt 4.8.

See Also▲

See also https://()

[since 5.0] void Q_UNREACHABLE▲

Tells the compiler that the current point cannot be reached by any execution, so it may optimize any code paths leading here as dead code, as well as code continuing from here.

This macro is useful to mark impossible conditions. For example, given the following enum:

 
Sélectionnez
   enum Shapes {
       Rectangle,
       Triangle,
       Circle,
       NumShapes
   };

One can write a switch table like so:

 
Sélectionnez
   switch (shape) {
       case Rectangle:
           return rectangle();
       case Triangle:
           return triangle();
       case Circle:
           return circle();
       case NumShapes:
           Q_UNREACHABLE();
           break;
   }

The advantage of inserting Q_UNREACHABLE() at that point is that the compiler is told not to generate code for a shape variable containing that value. If the macro is missing, the compiler will still generate the necessary comparisons for that value. If the case label were removed, some compilers could produce a warning that some enum values were not checked.

By using this macro in impossible conditions, code coverage may be improved as dead code paths may be eliminated.

In debug builds the condition is enforced by an assert to facilitate debugging.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://()

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.

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 https:// for details.

If you're worried about namespace pollution, you can disable this macro by adding the following line to your .pro file:

 
Sélectionnez
CONFIG += no_keywords

Since Qt 5.7, the use of this macro is discouraged. It will be removed in a future version of Qt. Please use C++11 range-for, possibly with https://(), as needed.

See Also▲

See also https://()

forever▲

This macro is provided for convenience for writing infinite loops.

Example:

 
Sélectionnez
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:

 
Sélectionnez
CONFIG += no_keywords
See Also▲

See also https://

qCritical(const char *message, ...)▲

Calls the message handler with the critical message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. On QNX the message is sent to slogger2.

It exits if the environment variable QT_FATAL_CRITICALS is not empty.

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:

 
Sélectionnez
void load(const QString &amp;fileName)
{
    QFile file(fileName);
    if (!file.exists())
        qCritical("File '%s' does not exist!", qUtf8Printable(fileName));
}

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

 
Sélectionnez
qCritical() &lt;&lt; "Brush:" &lt;&lt; myQBrush &lt;&lt; "Other
value:" &lt;&lt; i;

A space is inserted between the items, and a newline is appended at the end.

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

This macro is https://.

See Also▲

See also https://(), https://(), https://(), https://(), https://, Debugging Techniques

qDebug(const char *message, ...)▲

Calls the message handler with the debug message message. If no message handler has been installed, the message is printed to stderr. Under Windows the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. On QNX, the message is sent to slogger2. 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:

 
Sélectionnez
qDebug("Items in list: %d", myList.size());

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

 
Sélectionnez
qDebug() &lt;&lt; "Brush:" &lt;&lt; myQBrush &lt;&lt; "Other value:" &lt;&lt; i;

With this syntax, the function returns a https:// object that is configured to use the https:// message type. It automatically puts a single space between each item, and outputs a newline at the end. It supports many C++ and Qt types.

To suppress the output at run-time, install your own message handler with qInstallMessageHandler().

This macro is https://.

See Also▲

See also https://(), https://(), https://(), https://(), https://, Debugging Techniques

qFatal(const char *message, ...)▲

Calls the message handler with the fatal message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. On QNX the message is sent to slogger2.

If you are using the default message handler this function will abort 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:

 
Sélectionnez
int divide(int a, int b)
{
    if (b == 0)                                // program error
        qFatal("divide: cannot divide by zero");
    return a / b;
}

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

See Also▲

See also https://(), https://(), https://(), https://(), https://, Debugging Techniques

[since 5.5] qInfo(const char *message, ...)▲

Calls the message handler with the informational message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. On QNX the message is sent to slogger2. This function does nothing if QT_NO_INFO_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:

 
Sélectionnez
qInfo("Items in list: %d", myList.size());

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

 
Sélectionnez
qInfo() &lt;&lt; "Brush:" &lt;&lt; myQBrush &lt;&lt; "Other value:" &lt;&lt; i;

With this syntax, the function returns a https:// object that is configured to use the https:// message type. It automatically puts a single space between each item, and outputs a newline at the end. It supports many C++ and Qt types.

To suppress the output at run-time, install your own message handler with qInstallMessageHandler().

This macro is https://.

This macro was introduced in Qt 5.5.

See Also▲

See also https://(), https://(), https://(), https://(), https://, Debugging Techniques

qMove(x)▲

It expands to "std::move" if your compiler supports that C++11 function, or to nothing otherwise.

qMove takes an rvalue reference to its parameter x, and converts it to an xvalue.

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 QString::toLocal8Bit() will fall out of scope.

https://(), https://(), https://(), https://(), https://() expect %s arguments to be UTF-8 encoded, while qPrintable() converts to local 8-bit encoding. Therefore https://() should be used for logging strings instead of qPrintable().

See Also▲

See also https://()

[since 5.7] const wchar_t *qUtf16Printable(const QString &str)▲

Returns str as a const ushort *, but cast to a const wchar_t * to avoid warnings. This is equivalent to str.utf16() plus some casting.

The only useful thing you can do with the return value of this macro is to pass it to QString::asprintf() for use in a %ls conversion. In particular, the return value is not a valid const wchar_t*!

In general, the pointer will be invalid after the statement in which qUtf16Printable() is used. This is because the pointer may have been obtained from a temporary expression, which will fall out of scope.

Example:

 
Sélectionnez
qWarning("%ls: %ls", qUtf16Printable(key), qUtf16Printable(value));

This macro was introduced in Qt 5.7.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

[since 5.4] const char *qUtf8Printable(const QString &str)▲

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

The char pointer will be invalid after the statement in which qUtf8Printable() is used. This is because the array returned by QString::toUtf8() will fall out of scope.

Example:

 
Sélectionnez
qWarning("%s: %s", qUtf8Printable(key), qUtf8Printable(value));

This macro was introduced in Qt 5.4.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

qWarning(const char *message, ...)▲

Calls the message handler with the warning message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. On QNX the message is sent to slogger2. This function does nothing if QT_NO_WARNING_OUTPUT was defined during compilation; it exits if at the nth warning corresponding to the counter in environment variable QT_FATAL_WARNINGS. That is, if the environment variable contains the value 1, it will exit on the 1st message; if it contains the value 10, it will exit on the 10th message. Any non-numeric value is equivalent to 1.

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:

 
Sélectionnez
void f(int c)
{
    if (c &gt; 200)
        qWarning("f: bad argument, c == %d", c);
}

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

 
Sélectionnez
qWarning() &lt;&lt; "Brush:" &lt;&lt; myQBrush &lt;&lt; "Other value:"
&lt;&lt; i;

This syntax inserts a space between each item, and appends a newline at the end.

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

This macro is https://.

See Also▲

See also https://(), https://(), https://(), https://(), https://, Debugging Techniques

Obsolete Members for <QtGlobal>▲

The following members of class https:// are deprecated. We strongly advise against using them in new code.

Obsolete Function Documentation▲

 
[constexpr, since 4.2] int qrand()▲

This function is deprecated. We strongly advise against using it in new code.

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. Seeding must be performed at least once on each thread. If that step is skipped, then the sequence will be pre-seeded with a constant value.

This function is deprecated. In new applications, use https:// instead.

This function was introduced in Qt 4.2.

See Also▲

See also qrand(), https://

[constexpr, since 4.2] int qsrand(int seed)▲

This function is deprecated. We strongly advise against using it in new code.

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 https://().

The sequence of random numbers generated is deterministic per thread. For example, if two threads call qsrand(1) and subsequently call https://(), the threads will get the same random number sequence.

This function is deprecated. In new applications, use https:// instead.

This function was introduced in Qt 4.2.

See Also▲

See also https://(), https://

Obsolete Macro Documentation▲

 
QABS(n)▲

This macro is deprecated. We strongly advise against using it in new code.

Use qAbs(n) instead.

See Also▲

See also https://(), https://()

QMAX(x, y)▲

This macro is deprecated. We strongly advise against using it in new code.

Use qMax(x, y) instead.

See Also▲

See also https://(), https://()

QMIN(x, y)▲

This macro is deprecated. We strongly advise against using it in new code.

Use qMin(x, y) instead.

See Also▲

See also https://(), https://()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.