QUuid Class
The QUuid class stores a Universally Unique Identifier (UUID). More…
| Header | #include <QUuid> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | Variant |
| enum | Version |
| enum | StringFormat |
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) | |
| QString | toString(StringFormat mode = WithBraces) const |
| QByteArray | toByteArray(StringFormat mode = WithBraces) const |
| QByteArray | toRfc4122() const |
| bool | isNull() const |
| Variant | variant() const |
| Version | version() const |
| Id128Bytes | toBytes(QSysInfo::Endian order = QSysInfo::BigEndian) const |
Public Variables
Static Public Members
| QUuid | fromString(QAnyStringView text) |
| QUuid | fromBytes(const void *bytes, QSysInfo::Endian order = QSysInfo::BigEndian) |
| QUuid | fromRfc4122(const QByteArray &bytes) |
| QUuid | createUuid() |
| QUuid | createUuidV3(const QUuid &ns, const QByteArray &name) |
| QUuid | createUuidV5(const QUuid &ns, const QByteArray &name) |
| QUuid | createUuidV7() |
| QUuid | createUuidV3(const QUuid &ns, const QString &name) |
| QUuid | createUuidV5(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().
| Constant | Description |
|---|---|
QUuid::WithBraces | The canonical form with dashes, enclosed in braces: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. |
QUuid::WithoutBraces | The canonical form with dashes but without braces. |
QUuid::Id128 | The 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].
| Constant | Description |
|---|---|
QUuid::VarUnknown | The variant is unknown. A null UUID has this variant. |
QUuid::NCS | Reserved for NCS (Network Computing System) backward compatibility. |
QUuid::DCE | Distributed Computing Environment, the variant defined by RFC 4122. |
QUuid::Microsoft | Reserved for Microsoft Corporation backward compatibility. |
QUuid::Reserved | Reserved for future definition. |
See also variant().
enum QUuid::Version
Describes how a UUID of the DCE variant was generated.
| Constant | Description |
|---|---|
QUuid::VerUnknown | The version is unknown, or the UUID is not of the DCE variant. |
QUuid::Time | Time-based. |
QUuid::EmbeddedPOSIX | DCE security with embedded POSIX UIDs. |
QUuid::Md5 | Name-based, hashed with MD5. |
QUuid::Name | The same as Md5. |
QUuid::Random | Random-number based. |
QUuid::Sha1 | Name-based, hashed with SHA-1. |
QUuid::UnixEpoch | Time-ordered: a Unix timestamp in milliseconds followed by random bits (version 7). |
See also version().
Member Function Documentation
QUuid::QUuid()
Constructs the null UUID, with all fields zero.
See also isNull().
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.
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 *.
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().
QUuid QUuid::createUuid()
Creates a random (version 4, DCE variant) UUID using QRandomGenerator::system().
See also createUuidV3() and createUuidV5().
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().
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.
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().
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.
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().
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().
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().
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.