Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QUuid Class Reference

\inmodule QtCore More...

#include <quuid.h>

+ Inheritance diagram for QUuid:
+ Collaboration diagram for QUuid:

Classes

class  Id128Bytes
 \inmodule QtCore More...
 

Public Types

enum  Variant {
  VarUnknown =-1 , NCS = 0 , DCE = 2 , Microsoft = 6 ,
  Reserved = 7
}
 This enum defines the values used in the \l{Variant field} {variant field} of the UUID. More...
 
enum  Version {
  VerUnknown =-1 , Time = 1 , EmbeddedPOSIX = 2 , Md5 = 3 ,
  Name = Md5 , Random = 4 , Sha1 = 5 , UnixEpoch = 7
}
 This enum defines the values used in the \l{Version field} {version field} of the UUID. More...
 
enum  StringFormat { WithBraces = 0 , WithoutBraces = 1 , Id128 = 3 }
 

Public Member Functions

constexpr QUuid () noexcept
 Creates the null UUID.
 
constexpr QUuid (uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) noexcept
 Creates a UUID with the value specified by the parameters, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8.
 
 QUuid (Id128Bytes id128, QSysInfo::Endian order=QSysInfo::BigEndian) noexcept
 
 QUuid (QAnyStringView string) noexcept
 Creates a QUuid object from the string text, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex digit.
 
QString toString (StringFormat mode=WithBraces) const
 
QByteArray toByteArray (StringFormat mode=WithBraces) const
 
Id128Bytes toBytes (QSysInfo::Endian order=QSysInfo::BigEndian) const noexcept
 
QByteArray toRfc4122 () const
 Returns the binary representation of this QUuid.
 
constexpr bool isNull (QT6_DECL_NEW_OVERLOAD) const noexcept
 Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false.
 
constexpr Variant variant (QT6_DECL_NEW_OVERLOAD) const noexcept
 Returns the value in the \l{Variant field} {variant field} of the UUID.
 
constexpr Version version (QT6_DECL_NEW_OVERLOAD) const noexcept
 Returns the \l{Version field} {version field} of the UUID, if the UUID's \l{Variant field} {variant field} is QUuid::DCE.
 

Static Public Member Functions

static QUuid fromString (QAnyStringView string) noexcept
 
static QUuid fromBytes (const void *bytes, QSysInfo::Endian order=QSysInfo::BigEndian)
 
static QUuid fromRfc4122 (QByteArrayView) noexcept
 Creates a QUuid object from the binary representation of the UUID, as specified by RFC 4122 section 4.1.2.
 
static QUuid createUuid ()
 On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and version QUuid::Random.
 
static QUuid createUuidV5 (QUuid ns, QByteArrayView baseData) noexcept
 
static QUuid createUuidV3 (QUuid ns, QByteArrayView baseData) noexcept
 
static Q_WEAK_OVERLOAD QUuid createUuidV3 (const QUuid &ns, const QString &baseData)
 
static Q_WEAK_OVERLOAD QUuid createUuidV5 (const QUuid &ns, const QString &baseData)
 
static QUuid createUuidV7 ()
 

Public Attributes

uint data1
 
ushort data2
 
ushort data3
 
uchar data4 [8]
 

Friends

constexpr bool comparesEqual (const QUuid &lhs, const QUuid &rhs) noexcept
 
constexpr Qt::strong_ordering compareThreeWay (const QUuid &lhs, const QUuid &rhs) noexcept
 

Related Symbols

(Note that these are not member symbols.)

QUuid::Id128Bytes qFromBigEndian (QUuid::Id128Bytes src)
 
QUuid::Id128Bytes qFromLittleEndian (QUuid::Id128Bytes src)
 
QUuid::Id128Bytes qToBigEndian (QUuid::Id128Bytes src)
 
QUuid::Id128Bytes qToLittleEndian (QUuid::Id128Bytes src)
 
QDataStreamoperator<< (QDataStream &s, const QUuid &id)
 Writes the UUID id to the data stream s.
 
QDataStreamoperator>> (QDataStream &s, QUuid &id)
 Reads a UUID from the stream s into id.
 
QDebug operator<< (QDebug dbg, const QUuid &id)
 Writes the UUID id to the output stream for debugging information dbg.
 

Detailed Description

\inmodule QtCore

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

\reentrant

\compares strong \compareswith strong GUID

Note
Comparison with GUID is Windows-only. \endcompareswith

Using {U}niversally {U}nique {ID}entifiers (UUID) is a standard way to uniquely identify entities in a distributed computing environment. A UUID is a 16-byte (128-bit) number generated by some algorithm that is meant to guarantee that the UUID will be unique in the distributed computing environment where it is used. The acronym GUID is often used instead, {G}lobally {U}nique {ID}entifiers, but it refers to the same thing.

\target Variant field Actually, the GUID is one {variant} of UUID. Multiple variants are in use. Each UUID contains a bit field that specifies which type (variant) of UUID it is. Call variant() to discover which type of UUID an instance of QUuid contains. It extracts the three most significant bits of byte 8 of the 16 bytes. In QUuid, byte 8 is {QUuid::data4[0]}. If you create instances of QUuid using the constructor that accepts all the numeric values as parameters, use the following table to set the three most significant bits of parameter {b1}, which becomes {QUuid::data4[0]} and contains the variant field in its three most significant bits. In the table, 'x' means {don't care}.

\table \header

\row

  • 0
  • x
  • x
  • NCS (Network Computing System)

\row

  • 1
  • 0
  • x
  • DCE (Distributed Computing Environment)

\row

\row

  • 1
  • 1
  • 1
  • Reserved for future expansion

\endtable

\target Version field If variant() returns QUuid::DCE, the UUID also contains a {version} field in the four most significant bits of {QUuid::data3}, and you can call version() to discover which version your QUuid contains. If you create instances of QUuid using the constructor that accepts all the numeric values as parameters, use the following table to set the four most significant bits of parameter {w2}, which becomes {QUuid::data3} and contains the version field in its four most significant bits.

\table \header

\row

  • 0
  • 0
  • 0
  • 1
  • Time

\row

  • 0
  • 0
  • 1
  • 0
  • Embedded POSIX

\row

\row

  • 0
  • 1
  • 0
  • 0
  • Random

\row

  • 0
  • 1
  • 0
  • 1
  • Sha1

\endtable

The field layouts for the DCE versions listed in the table above are specified in the \l{RFC 4122} {Network Working Group UUID Specification}.

Most platforms provide a tool for generating new UUIDs, e.g. uuidgen and guidgen. You can also use createUuid(). UUIDs generated by createUuid() are of the random type. Their QUuid::Version bits are set to QUuid::Random, and their QUuid::Variant bits are set to QUuid::DCE. The rest of the UUID is composed of random numbers. Theoretically, this means there is a small chance that a UUID generated by createUuid() will not be unique. But it is \l{http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates} {a {very} small chance}.

UUIDs can be constructed from numeric values or from strings, or using the static createUuid() function. They can be converted to a string with toString(). UUIDs have a variant() and a version(), and null UUIDs return true from isNull().

Definition at line 32 of file quuid.h.

Member Enumeration Documentation

◆ StringFormat

Since
5.11

This enum is used by toString(StringFormat) to control the formatting of the string representation. The possible values are:

\value WithBraces The default, toString() will return five hex fields, separated by dashes and surrounded by braces. Example: {00000000-0000-0000-0000-000000000000}. \value WithoutBraces Only the five dash-separated fields, without the braces. Example: 00000000-0000-0000-0000-000000000000. \value Id128 Only the hex digits, without braces or dashes. Note that QUuid cannot parse this back again as input.

Enumerator
WithBraces 
WithoutBraces 
Id128 

Definition at line 55 of file quuid.h.

◆ Variant

This enum defines the values used in the \l{Variant field} {variant field} of the UUID.

The value in the variant field determines the layout of the 128-bit value.

\value VarUnknown Variant is unknown \value NCS Reserved for NCS (Network Computing System) backward compatibility \value DCE Distributed Computing Environment, the scheme used by QUuid \value Microsoft Reserved for Microsoft backward compatibility (GUID) \value Reserved Reserved for future definition

Enumerator
VarUnknown 
NCS 
DCE 
Microsoft 
Reserved 

Definition at line 36 of file quuid.h.

◆ Version

This enum defines the values used in the \l{Version field} {version field} of the UUID.

The version field is meaningful only if the value in the \l{Variant field} {variant field} is QUuid::DCE.

\value VerUnknown Version is unknown \value Time Time-based, by using timestamp, clock sequence, and MAC network card address (if available) for the node sections \value EmbeddedPOSIX DCE Security version, with embedded POSIX UUIDs \value Name Name-based, by using values from a name for all sections \value Md5 Alias for Name \value Random Random-based, by using random numbers for all sections \value Sha1 Name-based version that uses SHA-1 hashing \value UnixEpoch [since 6.9] Time-based UUID using the number of milliseconds since the UNIX epoch

Enumerator
VerUnknown 
Time 
EmbeddedPOSIX 
Md5 
Name 
Random 
Sha1 
UnixEpoch 

Definition at line 44 of file quuid.h.

Constructor & Destructor Documentation

◆ QUuid() [1/4]

QUuid::QUuid ( )
inlineconstexprnoexcept

Creates the null UUID.

toString() will output the null UUID as "{00000000-0000-0000-0000-000000000000}".

Definition at line 93 of file quuid.h.

◆ QUuid() [2/4]

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

Creates a UUID with the value specified by the parameters, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8.

Example:

// {67C8770B-44F1-410A-AB9A-F9B5446F13EE}
QUuid IID_MyInterface(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee);

Definition at line 95 of file quuid.h.

◆ QUuid() [3/4]

QUuid::QUuid ( Id128Bytes id128,
QSysInfo::Endian order = QSysInfo::BigEndian )
inlineexplicitnoexcept
Since
6.6

Creates a QUuid based on the integral id128 parameter. The input id128 parameter is considered to have byte order order.

See also
fromBytes(), toBytes(), toRfc4122(), toUInt128()

Definition at line 351 of file quuid.h.

◆ QUuid() [4/4]

QUuid::QUuid ( QAnyStringView text)
inlineexplicitnoexcept

Creates a QUuid object from the string text, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex digit.

The curly braces shown here are optional, but it is normal to include them. If the conversion fails, a null UUID is created. See toString() for an explanation of how the five hex fields map to the public data members in QUuid.

Note
In Qt versions prior to 6.3, this constructor was an overload set consisting of QString, QByteArray and {const char*} instead of one constructor taking QAnyStringView.
See also
toString(), QUuid()

Definition at line 100 of file quuid.h.

Member Function Documentation

◆ createUuid()

QUuid QUuid::createUuid ( )
static

On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and version QUuid::Random.

On Windows, a GUID is generated using the Windows API and will be of the type that the API decides to create.

See also
variant(), version()

Definition at line 949 of file quuid.cpp.

◆ createUuidV3() [1/2]

static Q_WEAK_OVERLOAD QUuid QUuid::createUuidV3 ( const QUuid & ns,
const QString & baseData )
inlinestatic
Since
5.0

This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5. ns is the namespace and baseData is the basic data as described by RFC 4122.

See also
variant(), version(), createUuidV5(), createUuidV7()

Definition at line 268 of file quuid.h.

◆ createUuidV3() [2/2]

QUuid QUuid::createUuidV3 ( QUuid ns,
QByteArrayView baseData )
staticnoexcept
Since
5.0

This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5. ns is the namespace and baseData is the basic data as described by RFC 4122.

Note
In Qt versions prior to 6.8, this function took QByteArray, not QByteArrayView.
See also
variant(), version(), createUuidV5(), createUuidV7()

Definition at line 582 of file quuid.cpp.

◆ createUuidV5() [1/2]

static Q_WEAK_OVERLOAD QUuid QUuid::createUuidV5 ( const QUuid & ns,
const QString & baseData )
inlinestatic
Since
5.0

This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1. ns is the namespace and baseData is the basic data as described by RFC 4122.

See also
variant(), version(), createUuidV3()

Definition at line 276 of file quuid.h.

◆ createUuidV5() [2/2]

QUuid QUuid::createUuidV5 ( QUuid ns,
QByteArrayView baseData )
staticnoexcept
Since
5.0

This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1. ns is the namespace and baseData is the basic data as described by RFC 4122.

Note
In Qt versions prior to 6.8, this function took QByteArray, not QByteArrayView.
See also
variant(), version(), createUuidV3()

Definition at line 587 of file quuid.cpp.

◆ createUuidV7()

QUuid QUuid::createUuidV7 ( )
static
Since
6.9

This function returns a new UUID with variant QUuid::DCE and version QUuid::UnixEpoch.

It uses a time-ordered value field derived from the number of milliseconds since the UNIX Epoch as described by \l {https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7}{RFC9562}.

See also
variant(), version(), createUuidV3(), createUuidV5()

Definition at line 604 of file quuid.cpp.

◆ fromBytes()

QUuid QUuid::fromBytes ( const void * bytes,
QSysInfo::Endian order = QSysInfo::BigEndian )
inlinestatic
Since
6.6

Reads 128 bits (16 bytes) from bytes using byte order order and returns the QUuid corresponding to those bytes. This function does the same as fromRfc4122() if the byte order order is QSysInfo::BigEndian.

See also
fromRfc4122()

Definition at line 376 of file quuid.h.

◆ fromRfc4122()

QUuid QUuid::fromRfc4122 ( QByteArrayView bytes)
staticnoexcept

Creates a QUuid object from the binary representation of the UUID, as specified by RFC 4122 section 4.1.2.

See toRfc4122() for a further explanation of the order of bytes required.

The byte array accepted is NOT a human readable format.

If the conversion fails, a null UUID is created.

Note
In Qt versions prior to 6.3, this function took QByteArray, not QByteArrayView.
Since
4.8
See also
toRfc4122(), QUuid(), fromBytes()

Definition at line 625 of file quuid.cpp.

◆ fromString()

QUuid QUuid::fromString ( QAnyStringView string)
staticnoexcept
Since
5.10

Creates a QUuid object from the string string, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex digit. The curly braces shown here are optional, but it is normal to include them. If the conversion fails, a null UUID is returned. See toString() for an explanation of how the five hex fields map to the public data members in QUuid.

Note
In Qt versions prior to 6.3, this function was an overload set consisting of QStringView and QLatin1StringView instead of one function taking QAnyStringView.
See also
toString(), QUuid()

Definition at line 532 of file quuid.cpp.

◆ isNull()

bool QUuid::isNull ( QT6_DECL_NEW_OVERLOAD ) const
inlineconstexprnoexcept

Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false.

Definition at line 124 of file quuid.h.

◆ toByteArray()

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

Returns the string representation of this QUuid, with the formattiong controlled by the mode parameter. From left to right, the five hex fields are obtained from the four public data members in QUuid as follows:

\table \header

  • Field #
  • Source

\row

  • 1
  • data1

\row

  • 2
  • data2

\row

  • 3
  • data3

\row

  • 4
  • data4[0] .. data4[1]

\row

  • 5
  • data4[2] .. data4[7]

\endtable

Definition at line 721 of file quuid.cpp.

◆ toBytes()

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

Returns a 128-bit ID created from this QUuid on the byte order specified by order. The binary content of this function is the same as toRfc4122() if the order is QSysInfo::BigEndian. See that function for more details.

See also
toRfc4122(), fromBytes(), QUuid()

Definition at line 364 of file quuid.h.

◆ toRfc4122()

QByteArray QUuid::toRfc4122 ( ) const

Returns the binary representation of this QUuid.

The byte array is in big endian format, and formatted according to RFC 4122, section 4.1.2 - "Layout and byte order".

The order is as follows:

\table \header

  • Field #
  • Source

\row

  • 1
  • data1

\row

  • 2
  • data2

\row

  • 3
  • data3

\row

  • 4
  • data4[0] .. data4[7]

\endtable

The bytes in the byte array returned by this function contains the same binary content as toBytes().

See also
toBytes()
Since
4.8

Definition at line 765 of file quuid.cpp.

◆ toString()

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

Returns the string representation of this QUuid, with the formattiong controlled by the mode parameter. From left to right, the five hex fields are obtained from the four public data members in QUuid as follows:

\table \header

  • Field #
  • Source

\row

  • 1
  • data1

\row

  • 2
  • data2

\row

  • 3
  • data3

\row

  • 4
  • data4[0] .. data4[1]

\row

  • 5
  • data4[2] .. data4[7]

\endtable

Definition at line 680 of file quuid.cpp.

◆ variant()

Variant QUuid::variant ( QT6_DECL_NEW_OVERLOAD ) const
inlineconstexprnoexcept

Returns the value in the \l{Variant field} {variant field} of the UUID.

If the return value is QUuid::DCE, call version() to see which layout it uses. The null UUID is considered to be of an unknown variant.

See also
version()

Definition at line 305 of file quuid.h.

◆ version()

Version QUuid::version ( QT6_DECL_NEW_OVERLOAD ) const
inlineconstexprnoexcept

Returns the \l{Version field} {version field} of the UUID, if the UUID's \l{Variant field} {variant field} is QUuid::DCE.

Otherwise it returns QUuid::VerUnknown.

See also
variant()

Definition at line 315 of file quuid.h.

Friends And Related Symbol Documentation

◆ comparesEqual

bool comparesEqual ( const QUuid & lhs,
const QUuid & rhs )
friend

Definition at line 147 of file quuid.h.

◆ compareThreeWay

Qt::strong_ordering compareThreeWay ( const QUuid & lhs,
const QUuid & rhs )
friend

Definition at line 180 of file quuid.h.

◆ operator<<() [1/2]

QDataStream & operator<< ( QDataStream & s,
const QUuid & id )
related

Writes the UUID id to the data stream s.

Definition at line 776 of file quuid.cpp.

◆ operator<<() [2/2]

QDebug operator<< ( QDebug dbg,
const QUuid & id )
related

Writes the UUID id to the output stream for debugging information dbg.

Definition at line 982 of file quuid.cpp.

◆ operator>>()

QDataStream & operator>> ( QDataStream & s,
QUuid & id )
related

Reads a UUID from the stream s into id.

Definition at line 814 of file quuid.cpp.

Member Data Documentation

◆ data1

uint QUuid::data1

Definition at line 332 of file quuid.h.

◆ data2

ushort QUuid::data2

Definition at line 333 of file quuid.h.

◆ data3

ushort QUuid::data3

Definition at line 334 of file quuid.h.

◆ data4

uchar QUuid::data4[8]

Definition at line 335 of file quuid.h.


The documentation for this class was generated from the following files: