Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions

<QtGlobal> - Global Qt Declarations

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

Types

Functions


Detailed Description

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

See also <QtAlgorithms>.


Type Documentation

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

typedef qint8

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

typedef qlonglong

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

typedef quint16

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

typedef quint32

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

typedef quint8

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

typedef qulonglong

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

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!", filename.local8bit());
    }

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("my window handle = %x", myWidget->id());

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(); // deliberately core dump
        }
    }

    int main(int argc, char **argv)
    {
        qInstallMsgHandler(myMessageOutput);
        QApplication a(argc, argv);
        ...
        return a.exec();
    }

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

int qMacVersion ()

Use QSysInfo::MacintoshVersion instead.

See also QSysInfo.

const T & qMax ( const T & a, const T & b )

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

int qRound ( double value )

Rounds value up to the nearest integer.

qint64 qRound64 ( double d )

Rounds value up to the nearest 64-bit integer.

const char * qVersion ()

Returns the Qt version number as a string, for example, "2.3.0" or "3.0.5".

The QT_VERSION define has the numeric value in the form: 0xMMIIPP (M = major, I = minor, B = patch). For example, Qt 3.0.5's QT_VERSION is 0x030005.

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.

void qt_check_pointer ( const char * n, int l )

\macrovoid 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.

This is really a macro defined in qglobal.h.

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.


Copyright © 2005 Trolltech Trademarks
Qt 4.0.0-rc1