Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

<QtGlobal> - Global Qt Declarations

The <QtGlobal> header file provides basic declarations and is included by all other Qt headers. More...

Types

Functions

  • T qAbs ( const T & value )
  • const T & qBound ( const T & min, const T & value, const T & max )
  • void qCritical ( const char * msg, ... )
  • void qDebug ( const char * msg, ... )
  • void qFatal ( const char * msg, ... )
  • QtMsgHandler qInstallMsgHandler ( QtMsgHandler h )
  • const T & qMax ( const T & value1, const T & value2 )
  • const T & qMin ( const T & value1, const T & value2 )
  • qint64 qRound64 ( double value )
  • int qRound ( double value )
  • const char * qVersion ()
  • void qWarning ( const char * msg, ... )

Macros


Detailed Description

The <QtGlobal> header file provides basic declarations and is included by all other Qt headers.

See also <QtAlgorithms>.


Type Documentation

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 that type can be created using the Q_INT64_C() macro:

    qint64 value = Q_INT64_C(932838457459459);

See also Q_INT64_C() and quint64.

typedef qlonglong

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

See also Q_INT64_C() and qulonglong.

typedef qreal

Typedef for double.

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 that type can be created using the Q_UINT64_C() macro:

    quint64 value = Q_UINT64_C(932838457459459);

See also Q_UINT64_C() and qint64.

typedef qulonglong

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

See also Q_UINT64_C() 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.

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

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 &fileName)
    {
        QFile file(fileName);
        if (!file.exists())
            qCritical("File '%s' does not exist!", qPrintable(fileName));
    }

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

Warning: Passing (const char *)0 as argument to qCritical might lead to crashes on certain platforms due to the platforms printf implementation.

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.

Warning: Passing (const char *)0 as argument to qDebug might lead to crashes on certain platforms due to the platform's printf() implementation.

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.

Warning: Passing (const char *)0 as argument to qFatal might lead to crashes on certain platforms due to the platforms printf implementation.

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

QtMsgHandler qInstallMsgHandler ( QtMsgHandler h )

Installs a Qt message handler h. Returns a pointer to the message handler previously defined.

The message handler is a function that prints out debug messages, warnings 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(), qFatal(), 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.

See also qMin() and qBound().

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

Returns the minimum of value1 and value2.

See also qMax() and qBound().

qint64 qRound64 ( double value )

Rounds value up to the nearest 64-bit integer.

int qRound ( double value )

Rounds value up to the nearest integer.

const char * qVersion ()

Returns the version number of the Qt runtime as a string (for example, "4.1.2"). This may be a different version than the version against which the application was compiled.

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);
    }

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

Warning: Passing (const char *)0 as argument to qWarning might lead to crashes on certain platforms due to the platforms printf implementation.

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


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 translation in the given context. Expands to sourceText.

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]);
    }

See also QT_TR_NOOP() and Internationalization with Qt.

const char * QT_TR_NOOP ( const char * sourceText )

Marks the string literal sourceText for translation in the current context. Expands to sourceText.

Example:

    QString FriendlyConversation::greeting(int type)
    {
        static const char *greeting_strings[] = {
            QT_TR_NOOP("Hello"),
            QT_TR_NOOP("Goodbye")
        };
        return tr(greeting_strings[type]);
    }

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_CC_BOR

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

Q_CC_CDS

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

Q_CC_COMEAU

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

Q_CC_DEC

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

Q_CC_EDG

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

Q_CC_GHS

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

Q_CC_GNU

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

Q_CC_HIGHC

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

Q_CC_HPACC

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

Q_CC_INTEL

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

Q_CC_KAI

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

Q_CC_MIPS

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

Q_CC_MSVC

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

Q_CC_MWERKS

Defined if the the application is compiled using Metrowerks CodeWarrior.

Q_CC_OC

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

Q_CC_PGI

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

Q_CC_SUN

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

Q_CC_SYM

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

Q_CC_USLC

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

Q_CC_WAT

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

void Q_CHECK_PTR ( void * p )

If p is 0, prints a warning message containing the source code 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_FOREACH ( variable, container )

Same as foreach(variable, container).

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_OS_X11

Defined for the X Window System.

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_MAC9

Defined for Mac OS 9.

Q_OS_MACX

Defined for Mac OS X.

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_QWS

Defined for Qt/Embedded.

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 Win32 (Windows 95/98/ME and Windows NT/2000/XP).

Q_OS_WIN32

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Defined for 32-bit 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().

foreach ( variable, container )

This macro is used to implement Qt's foreach loop. variable is a variable name or variable definition; container 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().

const char * qPrintable ( const QString & str )

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

Example:

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

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.0
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web