Home · All Classes · Modules

QtCore Module

The QtCore module contains core non-GUI functionality. More...

Types

Module Functions

Module Members


Detailed Description

The QtCore module contains non-GUI functionality.

All other PyQt modules rely on this module. To import the module use, for example, the following statement:

from PyQt4 import QtCore

Type Documentation

QtMsgType

This enum describes the messages that can be sent to a message handler (QtMsgHandler). You can use the enum to identify and associate the various message types with the appropriate actions.

Constant Value Description
QtDebugMsg 0 A message generated by the qDebug() function.
QtWarningMsg 1 A message generated by the qWarning() function.
QtCriticalMsg 2 A message generated by the qCritical() function.
QtFatalMsg 3 A message generated by the qFatal() function.
QtSystemMsg QtCriticalMsg


See also QtMsgHandler and qInstallMsgHandler().


Function Documentation

QTextStream bin (QTextStream s)

Calls QTextStream.setIntegerBase(2) on stream and returns stream.

See also oct(), dec(), hex(), and QTextStream manipulators.

QTextStream bom (QTextStream s)

Toggles insertion of the UTF-16 Byte Order Mark on stream when QTextStream is used with a UTF-16 codec.

See also QTextStream.setGenerateByteOrderMark() and QTextStream manipulators.

QTextStream center (QTextStream s)

Calls QTextStream.setFieldAlignment(QTextStream.AlignCenter) on stream and returns stream.

See also left(), right(), and QTextStream manipulators.

QTextStream dec (QTextStream s)

Calls QTextStream.setIntegerBase(10) on stream and returns stream.

See also bin(), oct(), hex(), and QTextStream manipulators.

QTextStream endl (QTextStream s)

Writes '\n' to the stream and flushes the stream.

Equivalent to

 stream << '\n' << flush;

Note: On Windows, all '\n' characters are written as '\r\n' if QTextStream's device or string is opened using the QIODevice.Text flag.

See also flush(), reset(), and QTextStream manipulators.

QTextStream fixed (QTextStream s)

Calls QTextStream.setRealNumberNotation(QTextStream.FixedNotation) on stream and returns stream.

See also scientific() and QTextStream manipulators.

QTextStream flush (QTextStream s)

Flushes any buffered data waiting to be written to the device.

If QTextStream operates on a string, this function does nothing.

QTextStream forcepoint (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() | QTextStream.ForcePoint) on stream and returns stream.

See also noforcepoint(), forcesign(), showbase(), and QTextStream manipulators.

QTextStream forcesign (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() | QTextStream.ForceSign) on stream and returns stream.

See also noforcesign(), forcepoint(), showbase(), and QTextStream manipulators.

QTextStream hex (QTextStream s)

Calls QTextStream.setIntegerBase(16) on stream and returns stream.

See also bin(), oct(), dec(), and QTextStream manipulators.

QTextStream left (QTextStream s)

Calls QTextStream.setFieldAlignment(QTextStream.AlignLeft) on stream and returns stream.

See also right(), center(), and QTextStream manipulators.

QTextStream lowercasebase (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() & ~QTextStream.UppercaseBase) on stream and returns stream.

See also uppercasebase(), lowercasedigits(), and QTextStream manipulators.

QTextStream lowercasedigits (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() & ~QTextStream.UppercaseDigits) on stream and returns stream.

See also uppercasedigits(), lowercasebase(), and QTextStream manipulators.

QTextStream noforcepoint (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() & ~QTextStream.ForcePoint) on stream and returns stream.

See also forcepoint(), noforcesign(), noshowbase(), and QTextStream manipulators.

QTextStream noforcesign (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() & ~QTextStream.ForceSign) on stream and returns stream.

See also forcesign(), noforcepoint(), noshowbase(), and QTextStream manipulators.

QTextStream noshowbase (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() & ~QTextStream.ShowBase) on stream and returns stream.

See also showbase(), noforcesign(), noforcepoint(), and QTextStream manipulators.

QTextStream oct (QTextStream s)

Calls QTextStream.setIntegerBase(8) on stream and returns stream.

See also bin(), dec(), hex(), and QTextStream manipulators.

pyqtRemoveInputHook ()

When the QtCore module is imported for the first time it installs a Python input hook (ie. it sets the value of Python's PyOS_InputHook variable). This allows commands to be entered at the interpreter prompt while the application is running. It is then possible to dynamically create new Qt objects and call the methods of any existing Qt object.

The input hook can cause problems for certain types of application, particularly those that provide a similar facility through different means. This function removes the input hook installed by PyQt.

The input hook can be restored using the pyqtRestoreInputHook() function.

pyqtRestoreInputHook ()

When the QtCore module is imported for the first time it installs a Python input hook (ie. it sets the value of Python's PyOS_InputHook variable). This allows commands to be entered at the interpreter prompt while the application is running. It is then possible to dynamically create new Qt objects and call the methods of any existing Qt object.

The input hook can cause problems for certain types of application, particularly those that provide a similar facility through different means, and so the pyqtRemoveInputHook() function is provided to remove it.

This function will restore the input hook if it has been removed.

object pyqtSignature (object)

object Q_ENUMS (...)

object Q_FLAGS (...)

float qAbs (float t)

Returns the absolute value of value. For example:

 int absoluteValue;
 int myValue = -4;

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

qAddPostRoutine (callable)

unsigned long qChecksum (str s)

Returns the CRC-16 checksum of the first len bytes of data.

The checksum is independent of the byte order (endianness).

QByteArray qCompress (QByteArray data, int compressionLevel = -1)

Compresses the data byte array and returns the compressed data in a new byte array.

The compressionLevel parameter specifies how much compression should be used. Valid values are between 0 and 9, with 9 corresponding to the greatest compression (i.e. smaller compressed data) at the cost of using a slower algorithm. Smaller values (8, 7, ..., 1) provide successively less compression at slightly faster speeds. The value 0 corresponds to no compression at all. The default value is -1, which specifies zlib's default compression.

See also qUncompress().

qCritical (str)

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

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

 qCritical() << "Brush:" << myQBrush << "Other
 value:" << i;

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

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

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

qDebug (str)

Calls the message handler with the debug message msg. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. This function does nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.

If you pass the function a format string and a list of arguments, it works in similar way to the C printf() function.

Example:

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

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

 qDebug() << "Brush:" << myQBrush << "Other value:" << i;

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

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

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

qErrnoWarning (int code, str msg)

qErrnoWarning (str msg)

qFatal (str)

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

For a release library this function will exit the application with return value 1. For the debug version this function will abort on Unix systems to create a core dump, and report a _CRT_ERROR on Windows allowing to connect a debugger to the application.

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

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

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

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

bool qFuzzyCompare (float p1, float p2)

unsigned long qHash (QBitArray key)

float qInf ()

callable qInstallMsgHandler (callable)

The callable argument may also be None.

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

The message handler is a function that prints out debug messages, warnings, critical and fatal error messages. The Qt library (debug version) contains hundreds of warning messages that are printed when internal errors (usually invalid function arguments) occur. If you implement your own message handler, you get total control of these messages.

The default message handler prints the message to the standard output under X11 or to the debugger under Windows. If it is a fatal message, the application aborts immediately.

Only one message handler can be defined, since this is usually done on an application-wide basis to control debug output.

To restore the message handler, call qInstallMsgHandler(0).

Example:

 #include <qapplication.h>
 #include <stdio.h>
 #include <stdlib.h>

 void myMessageOutput(QtMsgType type, const char *msg)
 {
     switch (type) {
     case QtDebugMsg:
         fprintf(stderr, "Debug: %s\n", msg);
         break;
     case QtWarningMsg:
         fprintf(stderr, "Warning: %s\n", msg);
         break;
     case QtCriticalMsg:
         fprintf(stderr, "Critical: %s\n", msg);
         break;
     case QtFatalMsg:
         fprintf(stderr, "Fatal: %s\n", msg);
         abort();
     }
 }

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

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

bool qIsFinite (float d)

bool qIsInf (float d)

bool qIsNaN (float d)

bool qIsNull (float d)

float qQNaN ()

int qrand ()

Thread-safe version of the standard C++ rand() function.

Returns a value between 0 and RAND_MAX (defined in <cstdlib> and <stdlib.h>), the next number in the current sequence of pseudo-random integers.

Use qsrand() to initialize the pseudo-random number generator with a seed value.

This function was introduced in Qt 4.2.

See also qsrand().

bool qRegisterResourceData (int, str, str, str)

qRemovePostRoutine (callable)

int qRound (float d)

Rounds value to the nearest integer. For example:

 qreal valueA = 2.3;
 qreal valueB = 2.7;

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

long qRound64 (float d)

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

 qreal valueA = 42949672960.3;
 qreal valueB = 42949672960.7;

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

QTextStreamManipulator qSetFieldWidth (int width)

Equivalent to QTextStream.setFieldWidth(width).

QTextStreamManipulator qSetPadChar (QChar ch)

Equivalent to QTextStream.setPadChar(ch).

QTextStreamManipulator qSetRealNumberPrecision (int precision)

Equivalent to QTextStream.setRealNumberPrecision(precision).

bool qSharedBuild ()

float qSNaN ()

qsrand (unsigned long seed)

Thread-safe version of the standard C++ srand() function.

Sets the argument seed to be used to generate a new random number sequence of pseudo random integers to be returned by qrand().

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

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

This function was introduced in Qt 4.2.

See also qrand().

int qstrcmp (str str1, str str2)

A safe strcmp() function.

Compares str1 and str2. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.

Special case 1: Returns 0 if str1 and str2 are both 0.

Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).

See also qstrncmp(), qstricmp(), qstrnicmp(), and Note on 8-bit character comparisons.

str qstrcpy (str dst, str src)

Copies all the characters up to and including the '\0' from src into dst and returns a pointer to dst. If src is 0, it immediately returns 0.

This function assumes that dst is large enough to hold the contents of src.

See also qstrncpy().

str qstrdup (str)

Returns a duplicate string.

Allocates space for a copy of src, copies it, and returns a pointer to the copy. If src is 0, it immediately returns 0.

Ownership is passed to the caller, so the returned string must be deleted using delete[].

int qstricmp (str, str)

A safe stricmp() function.

Compares str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1.

Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.

Special case 1: Returns 0 if str1 and str2 are both 0.

Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).

See also qstrcmp(), qstrncmp(), qstrnicmp(), and Note on 8-bit character comparisons.

unsigned long qstrlen (str str)

A safe strlen() function.

Returns the number of characters that precede the terminating '\0', or 0 if str is 0.

See also qstrnlen().

int qstrncmp (str str1, str str2, unsigned long len)

A safe strncmp() function.

Compares at most len bytes of str1 and str2.

Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.

Special case 1: Returns 0 if str1 and str2 are both 0.

Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).

See also qstrcmp(), qstricmp(), qstrnicmp(), and Note on 8-bit character comparisons.

str qstrncpy (str dst, str src, unsigned long len)

A safe strncpy() function.

Copies at most len bytes from src (stopping at len or the terminating '\0' whichever comes first) into dst and returns a pointer to dst. Guarantees that dst is '\0'-terminated. If src or dst is 0, returns 0 immediately.

This function assumes that dst is at least len characters long.

See also qstrcpy().

int qstrnicmp (str, str, unsigned long len)

A safe strnicmp() function.

Compares at most len bytes of str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1.

Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.

Special case 1: Returns 0 if str1 and str2 are both 0.

Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).

See also qstrcmp(), qstrncmp(), qstricmp(), and Note on 8-bit character comparisons.

unsigned long qstrnlen (str str, unsigned long maxlen)

qSwap (QBitArray value1, QBitArray value2)

qSwap (QByteArray value1, QByteArray value2)

qSwap (QString value1, QString value2)

qSwap (QUrl value1, QUrl value2)

qSwap (QVariant value1, QVariant value2)

object QT_TR_NOOP (object)

Marks the string literal sourceText for dynamic translation in the current context (class), i.e the stored sourceText will not be altered. For example:

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

The macro expands to sourceText.

See also QT_TRANSLATE_NOOP() and Internationalization with Qt.

object QT_TRANSLATE_NOOP (object, object)

Marks the string literal sourceText for dynamic translation in the given context, i.e the stored sourceText will not be altered. The context is typically a class. For example:

 static const char *greeting_strings[] = {
     QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
     QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
 };

 QString FriendlyConversation.greeting(int type)
 {
     return tr(greeting_strings[type]);
 }

 QString global_greeting(int type)
 {
     return qApp->translate("FriendlyConversation",
                            greeting_strings[type]);
 }

The macro expands to sourceText.

See also QT_TR_NOOP() and Internationalization with Qt.

QByteArray qUncompress (QByteArray data)

Uncompresses the data byte array and returns a new byte array with the uncompressed data.

Returns an empty QByteArray if the input data was corrupt.

This function will uncompress data compressed with qCompress() from this and any earlier Qt version, back to Qt 3.1 when this feature was added.

Note: If you want to use this function to uncompress external data compressed using zlib, you first need to prepend four bytes to the byte array that contain the expected length of the uncompressed data encoded in big-endian order (most significant byte first).

See also qCompress().

bool qUnregisterResourceData (int, str, str, str)

str qVersion ()

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

See also QT_VERSION_STR.

qWarning (str)

Calls the message handler with the warning message msg. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. This function does nothing if QT_NO_WARNING_OUTPUT was defined during compilation; it exits if the environment variable QT_FATAL_WARNINGS is defined.

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

 void f(int c)
 {
     if (c > 200)
         qWarning("f: bad argument, c == %d", c);
 }

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

 qWarning() << "Brush:" << myQBrush << "Other value:"
 << i;

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

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

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

QTextStream reset (QTextStream s)

Resets QTextStream's formatting options, bringing it back to its original constructed state. The device, string and any buffered data is left untouched.

QTextStream right (QTextStream s)

Calls QTextStream.setFieldAlignment(QTextStream.AlignRight) on stream and returns stream.

See also left(), center(), and QTextStream manipulators.

QTextStream scientific (QTextStream s)

Calls QTextStream.setRealNumberNotation(QTextStream.ScientificNotation) on stream and returns stream.

See also fixed() and QTextStream manipulators.

QTextStream showbase (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() | QTextStream.ShowBase) on stream and returns stream.

See also noshowbase(), forcesign(), forcepoint(), and QTextStream manipulators.

object SIGNAL (str)

object SLOT (str)

QTextStream uppercasebase (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() | QTextStream.UppercaseBase) on stream and returns stream.

See also lowercasebase(), uppercasedigits(), and QTextStream manipulators.

QTextStream uppercasedigits (QTextStream s)

Calls QTextStream.setNumberFlags(QTextStream.numberFlags() | QTextStream.UppercaseDigits) on stream and returns stream.

See also lowercasedigits(), uppercasebase(), and QTextStream manipulators.

QTextStream ws (QTextStream s)

Calls skipWhiteSpace() on stream and returns stream.

See also QTextStream manipulators.


Member Documentation

int PYQT_VERSION

This member should be treated as a constant.

str PYQT_VERSION_STR

This member should be treated as a constant.

int QT_VERSION

This member should be treated as a constant.

str QT_VERSION_STR

This member should be treated as a constant.


PyQt 4.3.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2007Qt 4.3.0