Functions

qCompress(data[, compressionLevel=-1])
Parameters:
Return type:

QByteArray

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(const QByteArray &data)()

qCompress(data, nbytes[, compressionLevel=-1])
Parameters:
  • data – str

  • nbytes – int

  • compressionLevel – int

Return type:

QByteArray

This is an overloaded function.

Compresses the first nbytes of data at compression level compressionLevel and returns the compressed data in a new byte array.

qFastCos(x)
Parameters:

x – float

Return type:

float

Added in version 4.6.

qFastSin(x)
Parameters:

x – float

Return type:

float

Added in version 4.6.

qFormatLogMessage(type, context, buf)
Parameters:
Return type:

str

Generates a formatted string out of the type, context, str arguments.

qFormatLogMessage returns a QString that is formatted according to the current message pattern. It can be used by custom message handlers to format output similar to Qt’s default message handler.

The function is thread-safe.

qFuzzyCompare(p1, p2)
Parameters:
  • p1 – float

  • p2 – float

Return type:

bool

qFuzzyCompare(q1, q2)
Parameters:
Return type:

bool

qFuzzyCompare(t1, t2)
Parameters:
Return type:

bool

qFuzzyIsNull(d)
Parameters:

d – float

Return type:

bool

Added in version 4.6.

qIsFinite(d)
Parameters:

d – float

Return type:

bool

qIsInf(d)
Parameters:

d – float

Return type:

bool

qIsNaN(d)
Parameters:

d – float

Return type:

bool

qIsNull(d)
Parameters:

d – float

Return type:

bool

qSetMessagePattern(messagePattern)
Parameters:

messagePattern – str

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Changes the output of the default message handler.

Allows to tweak the output of qDebug() , qInfo() , qWarning() , qCritical() , and qFatal() . The category logging output of qCDebug() , qCInfo() , qCWarning() , and qCCritical() is formatted, too.

Following placeholders are supported:

Placeholder

Description

%{appname}

applicationName()

%{category}

Logging category

%{file}

Path to source file

%{function}

Function

%{line}

Line in source file

%{message}

The actual message

%{pid}

applicationPid()

%{threadid}

The system-wide ID of current thread (if it can be obtained)

%{qthreadptr}

A pointer to the current QThread (result of currentThread() )

%{type}

“debug”, “warning”, “critical” or “fatal”

%{time process}

time of the message, in seconds since the process started (the token “process” is literal)

%{time boot}

the time of the message, in seconds since the system boot if that can be determined (the token “boot” is literal). If the time since boot could not be obtained, the output is indeterminate (see msecsSinceReference() ).

%{time [format]}

system time when the message occurred, formatted by passing the format to toString() . If the format is not specified, the format of ISODate is used.

%{backtrace [depth=N] [separator="..."]}

A backtrace with the number of frames specified by the optional depth parameter (defaults to 5), and separated by the optional separator parameter (defaults to “|”).

This expansion is available only on some platforms:

  • platforms using glibc;

  • platforms shipping C++23’s <stacktrace> header (requires compiling Qt in C++23 mode).

Depending on the platform, there are some restrictions on the function names printed by this expansion.

On some platforms, names are only known for exported functions. If you want to see the name of every function in your application, make sure your application is compiled and linked with -rdynamic, or an equivalent of it.

When reading backtraces, take into account that frames might be missing due to inlining or tail call optimization.

You can also use conditionals on the type of the message using %{if-debug}, %{if-info} %{if-warning}, %{if-critical} or %{if-fatal} followed by an %{endif}. What is inside the %{if-*} and %{endif} will only be printed if the type matches.

Finally, text inside %{if-category}%{endif} is only printed if the category is not the default one.

Example:

QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"

The default pattern is %{if-category}%{category}: %{endif}%{message}.

The pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is set, the environment variable takes precedence.

Note

The information for the placeholders category, file, function and line is only recorded in debug builds. Alternatively, QT_MESSAGELOGCONTEXT can be defined explicitly. For more information refer to the QMessageLogContext documentation.

Note

The message pattern only applies to unstructured logging, such as the default stderr output. Structured logging such as systemd will record the message as is, along with as much structured information as can be captured.

Custom message handlers can use qFormatLogMessage() to take pattern into account.

qUncompress(data, nbytes)
Parameters:
  • data – str

  • nbytes – int

Return type:

QByteArray

This is an overloaded function.

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

qUncompress(data)
Parameters:

dataQByteArray

Return type:

QByteArray

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 that was compressed using zlib, you first need to prepend a four byte header to the byte array containing the data. The header must contain the expected length (in bytes) of the uncompressed data, expressed as an unsigned, big-endian, 32-bit integer. This number is just a hint for the initial size of the output buffer size, though. If the indicated size is too small to hold the result, the output buffer size will still be increased until either the output fits or the system runs out of memory. So, despite the 32-bit header, this function, on 64-bit platforms, can produce more than 4GiB of output.

Note

In Qt versions prior to Qt 6.5, more than 2GiB of data worked unreliably; in Qt versions prior to Qt 6.0, not at all.

See also

qCompress()

qVersion()
Return type:

str

qtTrId(id[, n=-1])
Parameters:
  • id – str

  • n – int

Return type:

str

Added in version 4.6.

qDebug(message)
Parameters:

message – str

qCritical(message)
Parameters:

message – str

qFatal(message)
Parameters:

message – str

qInfo(message)
Parameters:

message – str

qWarning(message)
Parameters:

message – str

Q_ARG(type, value)
Parameters:
  • type – object

  • value – object

Return type:

QGenericArgumentHolder

This function takes a type (or a type string) and a value of that type and returns an internal object that can be passed to QMetaObject.invokeMethod(). See also Q_RETURN_ARG().

Q_RETURN_ARG(type)
Parameters:

type – object

Return type:

QGenericReturnArgumentHolder

This macro takes a type (or a type string) a value of which is then returned by QMetaObject.invokeMethod(). See also Q_ARG().

__init_feature__()
qAbs(arg__1)
Parameters:

arg__1 – float

Return type:

float

qAddPostRoutine(callable)
Parameters:

callable – object

__moduleShutdown()
qInstallMessageHandler(callable)
Parameters:

callable – object

Return type:

object

SIGNAL(signature)
Parameters:

signature – str

Return type:

str

SLOT(signature)
Parameters:

signature – str

Return type:

str

QT_TR_NOOP(message)
Parameters:

message – object

Return type:

object

QT_TR_NOOP_UTF8(message)
Parameters:

message – object

Return type:

object

QT_TRANSLATE_NOOP(context, message)
Parameters:
  • context – object

  • message – object

Return type:

object

QT_TRANSLATE_NOOP3(context, message, disambiguation)
Parameters:
  • context – object

  • message – object

  • disambiguation – object

Return type:

object

QT_TRANSLATE_NOOP_UTF8(message)
Parameters:

message – object

Return type:

object

qRegisterResourceData(arg__1, arg__2, arg__3, arg__4)
Parameters:
  • arg__1 – int

  • arg__2PyBytes

  • arg__3PyBytes

  • arg__4PyBytes

Return type:

bool

qUnregisterResourceData(arg__1, arg__2, arg__3, arg__4)
Parameters:
  • arg__1 – int

  • arg__2PyBytes

  • arg__3PyBytes

  • arg__4PyBytes

Return type:

bool

qCDebug(logging_category, message)
Parameters:
qCCritical(logging_category, message)
Parameters:
qCInfo(logging_category, message)
Parameters:
qCWarning(logging_category, message)
Parameters:

Enumerations

class QCborKnownTags

This enum contains a list of CBOR tags, known at the time of the Qt implementation. This list is not meant to be complete and contains only tags that are either backed by an RFC or specifically used by the Qt implementation.

The authoritative list is maintained by IANA in the CBOR tag registry .

Constant

Description

QCborKnownTags.DateTimeString

A date and time string, formatted according to RFC 3339, as refined by RFC 4287. It is the same format as ISODate and ISODateWithMs .

QCborKnownTags.UnixTime_t

A numerical representation of seconds elapsed since 1970-01-01T00:00Z.

QCborKnownTags.PositiveBignum

A positive number of arbitrary length, encoded as a byte array in network byte order. For example, the number 2 64 is represented by a byte array containing the byte value 0x01 followed by 8 zero bytes.

QCborKnownTags.NegativeBignum

A negative number of arbitrary length, encoded as the absolute value of that number, minus one. For example, a byte array containing byte value 0x02 followed by 8 zero bytes represents the number -2 65 - 1.

QCborKnownTags.Decimal

A decimal fraction, encoded as an array of two integers: the first is the exponent of the power of 10, the second the integral mantissa. The value 273.15 would be encoded as array [-2, 27315].

QCborKnownTags.Bigfloat

Similar to Decimal, but the exponent is a power of 2 instead.

QCborKnownTags.COSE_Encrypt0

An Encrypt0 map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.COSE_Mac0

A Mac0 map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.COSE_Sign1

A Sign1 map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.ExpectedBase64url

Indicates that the byte array should be encoded using Base64url if the stream is converted to JSON.

QCborKnownTags.ExpectedBase64

Indicates that the byte array should be encoded using Base64 if the stream is converted to JSON.

QCborKnownTags.ExpectedBase16

Indicates that the byte array should be encoded using Base16 (hex) if the stream is converted to JSON.

QCborKnownTags.EncodedCbor

Indicates that the byte array contains a CBOR stream.

QCborKnownTags.Url

Indicates that the string contains a URL.

QCborKnownTags.Base64url

Indicates that the string contains data encoded using Base64url.

QCborKnownTags.Base64

Indicates that the string contains data encoded using Base64.

QCborKnownTags.RegularExpression

Indicates that the string contains a Perl-Compatible Regular Expression pattern.

QCborKnownTags.MimeMessage

Indicates that the string contains a MIME message (according to RFC 2045).

QCborKnownTags.Uuid

Indicates that the byte array contains a UUID.

QCborKnownTags.COSE_Encrypt

An Encrypt map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.COSE_Mac

A Mac map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.COSE_Sign

A Sign map as specified by RFC 8152 (CBOR Object Signing and Encryption).

QCborKnownTags.Signature

No change in interpretation; this tag can be used as the outermost tag in a CBOR stream as the file header.

The following tags are interpreted by QCborValue during decoding and will produce objects with extended Qt types, and it will use those tags when encoding the same extended types.

Constant

Description

QCborKnownTags.DateTimeString

QDateTime

QCborKnownTags.UnixTime_t

QDateTime (only in decoding)

QCborKnownTags.Url

QUrl

QCborKnownTags.Uuid

QUuid

Additionally, if a QCborValue containing a QByteArray is tagged using one of ExpectedBase64url, ExpectedBase64 or ExpectedBase16, QCborValue will use the expected encoding when converting to JSON (see toJsonValue ).

See also

QCborTag append(QCborTag) isTag() toTag() isTag() tag()

class QCborSimpleType

This enum contains the possible “Simple Types” for CBOR. Simple Types range from 0 to 255 and are types that carry no further value.

The following values are currently known:

Constant

Description

QCborSimpleType.False

A “false” boolean.

QCborSimpleType.True

A “true” boolean.

QCborSimpleType.Null

Absence of value (null).

QCborSimpleType.Undefined

Missing or deleted value, usually an error.

Qt CBOR API supports encoding and decoding any Simple Type, whether one of those above or any other value.

Applications should only use further values if a corresponding specification has been published, otherwise interpretation and validation by the remote may fail. Values 24 to 31 are reserved and must not be used.

The current authoritative list is maintained by IANA in the Simple Values registry .

See also

append(QCborSimpleType) isSimpleType() toSimpleType() isSimpleType() toSimpleType()

class QCborTag

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

This enum contains no enumeration and is used only to provide type-safe access to a CBOR tag.

CBOR tags are 64-bit numbers that are attached to generic CBOR types to provide further semantic meaning. QCborTag may be constructed from an enumeration found in QCborKnownTags or directly by providing the numeric representation.

For example, the following creates a QCborValue containing a byte array tagged with a tag 2.

QCborValue(QCborTag(2), QByteArray("\x01\0\0\0\0\0\0\0\0", 9))

See also

QCborKnownTags append(QCborTag) isTag() toTag() isTag() tag()

class QtMsgType

This enum describes the messages that can be sent to a message handler ( QtMessageHandler ). You can use the enum to identify and associate the various message types with the appropriate actions. Its values are, in order of increasing severity:

Constant

Description

QtDebugMsg

A message generated by the qDebug() function.

QtInfoMsg

A message generated by the qInfo() function.

QtWarningMsg

A message generated by the qWarning() function.

QtCriticalMsg

A message generated by the qCritical() function.

QtFatalMsg

A message generated by the qFatal() function.

See also

QtMessageHandler qInstallMessageHandler() QLoggingCategory