6.0.0-rc4Source

QUuid Class

The QUuid class stores a Universally Unique Identifier (UUID). More…

Header#include <QUuid>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QUuid()
QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)
QUuid(QAnyStringView text)
QUuid(Id128Bytes id128, QSysInfo::Endian order = QSysInfo::BigEndian)
QStringtoString(StringFormat mode = WithBraces) const
QByteArraytoByteArray(StringFormat mode = WithBraces) const
QByteArraytoRfc4122() const
boolisNull() const
Variantvariant() const
Versionversion() const
Id128BytestoBytes(QSysInfo::Endian order = QSysInfo::BigEndian) const

Public Variables

uintdata1
ushortdata2
ushortdata3
uchardata4

Static Public Members

QUuidfromString(QAnyStringView text)
QUuidfromBytes(const void *bytes, QSysInfo::Endian order = QSysInfo::BigEndian)
QUuidfromRfc4122(const QByteArray &bytes)
QUuidcreateUuid()
QUuidcreateUuidV3(const QUuid &ns, const QByteArray &name)
QUuidcreateUuidV5(const QUuid &ns, const QByteArray &name)
QUuidcreateUuidV7()
QUuidcreateUuidV3(const QUuid &ns, const QString &name)
QUuidcreateUuidV5(const QUuid &ns, const QString &name)

Detailed Description

A UUID is a 128-bit value, usually written as 32 hexadecimal digits in the form {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. createUuid() returns a random (version 4) UUID, and createUuidV3() and createUuidV5() derive one from a namespace and a name.

QUuid id = QUuid::createUuid();
QString text = id.toString(QUuid::WithoutBraces);

See also QRandomGenerator and QCryptographicHash.

Differences from Qt

There are no Windows GUID or Apple NSUUID conversions, and no toUInt128() or fromUInt128().

Member Type Documentation

enum QUuid::StringFormat

Selects the text format used by toString() and toByteArray().

ConstantDescription
QUuid::WithBracesThe canonical form with dashes, enclosed in braces: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.
QUuid::WithoutBracesThe canonical form with dashes but without braces.
QUuid::Id128The 32 hexadecimal digits with neither dashes nor braces.

enum QUuid::Variant

Describes the layout of a UUID, which is stored in the top bits of data4[0].

ConstantDescription
QUuid::VarUnknownThe variant is unknown. A null UUID has this variant.
QUuid::NCSReserved for NCS (Network Computing System) backward compatibility.
QUuid::DCEDistributed Computing Environment, the variant defined by RFC 4122.
QUuid::MicrosoftReserved for Microsoft Corporation backward compatibility.
QUuid::ReservedReserved for future definition.

See also variant().

enum QUuid::Version

Describes how a UUID of the DCE variant was generated.

ConstantDescription
QUuid::VerUnknownThe version is unknown, or the UUID is not of the DCE variant.
QUuid::TimeTime-based.
QUuid::EmbeddedPOSIXDCE security with embedded POSIX UIDs.
QUuid::Md5Name-based, hashed with MD5.
QUuid::NameThe same as Md5.
QUuid::RandomRandom-number based.
QUuid::Sha1Name-based, hashed with SHA-1.
QUuid::UnixEpochTime-ordered: a Unix timestamp in milliseconds followed by random bits (version 7).

See also version().

Member Function Documentation

[constexpr] QUuid::QUuid()

Constructs the null UUID, with all fields zero.

See also isNull().

[constexpr] QUuid::QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)

Constructs a UUID from the fields l, w1 and w2, and the eight bytes b1, b2, b3, b4, b5, b6, b7 and b8.

[explicit] QUuid::QUuid(QAnyStringView text)

Constructs a UUID by parsing text, as fromString() does. The text can be a QString, a QStringView, a QLatin1StringView, or UTF-8 text in a QByteArray or a const char *.

[explicit] QUuid::QUuid(Id128Bytes id128, QSysInfo::Endian order = QSysInfo::BigEndian)

Constructs a UUID from the 16 bytes of id128, which are in the byte order order.

This function was introduced in 6.6.

See also fromBytes() and toBytes().

[static] QUuid QUuid::createUuid()

Creates a random (version 4, DCE variant) UUID using QRandomGenerator::system().

See also createUuidV3() and createUuidV5().

[static] QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &name)

Creates a name-based, version 3 UUID by hashing name within the namespace ns with MD5. The same inputs always give the same UUID.

See also createUuidV5() and createUuid().

[static] QUuid QUuid::createUuidV3(const QUuid &ns, const QString &name)

This is an overloaded function.

Creates a version 3 UUID from name, converted to UTF-8, within the namespace ns.

[static] QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &name)

Creates a name-based, version 5 UUID by hashing name within the namespace ns with SHA-1. The same inputs always give the same UUID.

See also createUuidV3() and createUuid().

[static] QUuid QUuid::createUuidV5(const QUuid &ns, const QString &name)

This is an overloaded function.

Creates a version 5 UUID from name, converted to UTF-8, within the namespace ns.

[static] QUuid QUuid::createUuidV7()

Creates a time-ordered, version 7 UUID: the first 48 bits are the milliseconds since the Unix epoch, and the remaining bits other than the version and variant are random. UUIDs created by one process sort in the order they were created, even within the same millisecond, because a counter in the 12 bits after the version breaks ties.

This function was introduced in 6.9.

See also createUuid() and version().

[static] QUuid QUuid::fromBytes(const void *bytes, QSysInfo::Endian order = QSysInfo::BigEndian)

Returns the UUID held in the 16 bytes at bytes, which are in the byte order order. Returns a null UUID if bytes is nullptr.

const QUuid::Id128Bytes raw = uuid.toBytes();
QUuid::fromBytes(raw.data) == uuid;   // true

This function was introduced in 6.6.

See also toBytes() and fromRfc4122().

[static] QUuid QUuid::fromRfc4122(const QByteArray &bytes)

Creates a UUID from the 16 bytes in bytes, in network (big-endian) order. Returns a null UUID if bytes does not hold exactly 16 bytes.

See also toRfc4122().

[static] QUuid QUuid::fromString(QAnyStringView text)

Parses text as a UUID. It must be 32 hexadecimal digits, or the canonical dashed form, optionally enclosed in braces. Digits may be upper or lower case. Returns a null UUID if text is not valid.

text can be a QString, a QStringView, a QLatin1StringView, or UTF-8 text in a QByteArray or a const char *.

See also toString().

bool QUuid::isNull() const

Returns true if all fields are zero; otherwise returns false.

QByteArray QUuid::toByteArray(StringFormat mode = WithBraces) const

Returns the UUID as lowercase hexadecimal text, as a QByteArray, in the given mode.

See also toString() and fromString().

Id128Bytes QUuid::toBytes(QSysInfo::Endian order = QSysInfo::BigEndian) const

Returns the 16 bytes of the UUID in the byte order order. With QSysInfo::BigEndian, the default, they are the bytes of toRfc4122(); with QSysInfo::LittleEndian they are in the reverse order.

This function was introduced in 6.6.

See also fromBytes() and toRfc4122().

QByteArray QUuid::toRfc4122() const

Returns the UUID as 16 bytes in network (big-endian) order, as defined by RFC 4122.

See also fromRfc4122().

QString QUuid::toString(StringFormat mode = WithBraces) const

Returns the UUID as lowercase hexadecimal text in the given mode.

See also toByteArray() and fromString().

Variant QUuid::variant() const

Returns the variant of the UUID, or VarUnknown if it is null.

See also version().

Version QUuid::version() const

Returns the version of the UUID, or VerUnknown if it is not of the DCE variant or has an unrecognized version.

See also variant().

Member Variable Documentation

uint QUuid::data1

The first 32 bits of the UUID.

ushort QUuid::data2

The next 16 bits of the UUID.

ushort QUuid::data3

The next 16 bits of the UUID, which hold the version in the top four bits.

uchar QUuid::data4

The last 64 bits of the UUID. The top bits of data4[0] hold the variant.