![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <quuid.h>
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 } |
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. | |
bool | isNull () const noexcept |
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false . | |
constexpr bool | operator== (const QUuid &orig) const noexcept |
Returns true if this QUuid and the other QUuid are identical; otherwise returns false . | |
constexpr bool | operator!= (const QUuid &orig) const noexcept |
Returns true if this QUuid and the other QUuid are different; otherwise returns false . | |
bool | operator< (const QUuid &other) const noexcept |
Returns true if this QUuid has the same \l{Variant field} {variant field} as the other QUuid and is lexicographically {before} the other QUuid. | |
bool | operator> (const QUuid &other) const noexcept |
Returns true if this QUuid has the same \l{Variant field} {variant field} as the other QUuid and is lexicographically {after} the other QUuid. | |
QUuid::Variant | variant () const noexcept |
Returns the value in the \l{Variant field} {variant field} of the UUID. | |
QUuid::Version | version () 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) noexcept |
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 | createUuidV3 (const QUuid &ns, const QByteArray &baseData) |
static QUuid | createUuidV5 (const QUuid &ns, const QByteArray &baseData) |
static QUuid | createUuidV3 (const QUuid &ns, const QString &baseData) |
static QUuid | createUuidV5 (const QUuid &ns, const QString &baseData) |
Public Attributes | |
uint | data1 = 0 |
ushort | data2 = 0 |
ushort | data3 = 0 |
uchar | data4 [8] = {} |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &s, const QUuid &id) |
Writes the UUID id to the data stream s. | |
QDataStream & | operator>> (QDataStream &s, QUuid &id) |
Reads a UUID from the stream s into id. | |
bool | operator<= (const QUuid &lhs, const QUuid &rhs) |
bool | operator>= (const QUuid &lhs, const QUuid &rhs) |
QDebug | operator<< (QDebug dbg, const QUuid &id) |
Writes the UUID id to the output stream for debugging information dbg. | |
size_t | qHash (const QUuid &uuid, size_t seed) noexcept |
\inmodule QtCore
The QUuid class stores a Universally Unique Identifier (UUID).
\reentrant
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
\row
\row
\row
\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
\row
\row
\row
\row
\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().
enum QUuid::StringFormat |
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 |
enum QUuid::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 |
enum QUuid::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
Enumerator | |
---|---|
VerUnknown | |
Time | |
EmbeddedPOSIX | |
Md5 | |
Name | |
Random | |
Sha1 |
|
inlineconstexprnoexcept |
Creates the null UUID.
toString() will output the null UUID as "{00000000-0000-0000-0000-000000000000}".
|
inlineconstexprnoexcept |
Creates a UUID with the value specified by the parameters, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8.
Example:
|
inlineexplicitnoexcept |
Creates a QUuid based on the integral id128 parameter and respecting the byte order order.
Definition at line 216 of file quuid.h.
References QSysInfo::LittleEndian.
|
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.
{const char*} instead of one constructor taking QAnyStringView.Definition at line 80 of file quuid.h.
References fromString().
|
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.
Definition at line 947 of file quuid.cpp.
References QRandomGenerator::fillRange(), QRandomGenerator::system(), and Qt::Uninitialized.
Referenced by QWindowsContext::registerWindowClass(), and QPdfEnginePrivate::writeTail().
|
static |
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.
Definition at line 520 of file quuid.cpp.
References createFromName(), and QCryptographicHash::Md5.
Referenced by createUuidV3().
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.
Definition at line 165 of file quuid.h.
References createUuidV3(), and QString::toUtf8().
|
static |
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.
Definition at line 526 of file quuid.cpp.
References createFromName(), and QCryptographicHash::Sha1.
Referenced by createUuidV5(), and writePrologue().
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.
Definition at line 171 of file quuid.h.
References createUuidV5(), and QString::toUtf8().
|
inlinestaticnoexcept |
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.
Definition at line 238 of file quuid.h.
Referenced by parseReadByTypeCharDiscovery(), and parseReadByTypeIncludeDiscovery().
|
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.
Definition at line 547 of file quuid.cpp.
Referenced by createFromName(), QMimerSQLResult::data(), maybeEncodeTag(), operator>>(), and QCborValue::toUuid().
|
staticnoexcept |
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.
Definition at line 475 of file quuid.cpp.
References text, and uuidFromString().
Referenced by QWindowsNativeFileDialogBase::shellItem().
|
noexcept |
Returns true
if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false
.
Definition at line 768 of file quuid.cpp.
References data1, data2, data3, and data4.
Referenced by QLowEnergyControllerPrivateDarwin::connectToDevice(), QBluetoothSocketPrivateBluezDBus::connectToService(), QBluetoothSocketPrivateBluezDBus::connectToService(), DarwinBluetooth::extract_service_record(), DarwinBluetooth::extract_services_uuids(), QBluetoothSocketPrivateAndroid::fallBackReversedConnect(), QLowEnergyCharacteristicData::isValid(), QLowEnergyDescriptorData::isValid(), QLowEnergyServiceData::isValid(), QBluetoothUuid::minimumSize(), QT_BEGIN_NAMESPACE::qt_createLEService(), QBluetoothSocketPrivateAndroid::reverseUuid(), QNetworkConnectionEvents::startMonitoring(), variant(), and version().
|
inlineconstexprnoexcept |
|
noexcept |
Returns true
if this QUuid has the same \l{Variant field} {variant field} as the other QUuid and is lexicographically {before} the other QUuid.
If the other QUuid has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}.
Definition at line 861 of file quuid.cpp.
References ISLESS, other(), and variant.
|
inlineconstexprnoexcept |
|
noexcept |
Returns true
if this QUuid has the same \l{Variant field} {variant field} as the other QUuid and is lexicographically {after} the other QUuid.
If the other QUuid has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}.
Definition at line 888 of file quuid.cpp.
References other().
QByteArray QUuid::toByteArray | ( | QUuid::StringFormat | mode = WithBraces | ) | const |
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
\row
\row
\row
\row
\row
\endtable
Definition at line 643 of file quuid.cpp.
References _q_uuidToHex(), MaxStringUuidLength, and Qt::Uninitialized.
Referenced by dumpAttributeVariant(), and QTest::toString().
|
inlinenoexcept |
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.
Definition at line 226 of file quuid.h.
References QSysInfo::LittleEndian, and qToBigEndian().
Referenced by DarwinBluetooth::cb_uuid(), DarwinBluetooth::iobluetooth_uuid(), putDataAndIncrement(), QBluetoothSocketPrivateAndroid::reverseUuid(), and 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
\row
\row
\row
\row
\endtable
The bytes in the byte array returned by this function contains the same binary content as toBytes().
Definition at line 687 of file quuid.cpp.
References QByteArrayView::toByteArray(), and toBytes().
QString QUuid::toString | ( | QUuid::StringFormat | mode = WithBraces | ) | const |
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
\row
\row
\row
\row
\row
\endtable
Definition at line 602 of file quuid.cpp.
References _q_uuidToHex(), QString::fromLatin1(), and MaxStringUuidLength.
Referenced by QCtfLibImpl::QCtfLibImpl(), QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(), QBluetoothSocketPrivateAndroid::connectToServiceHelper(), QBluetoothSocketPrivateAndroid::fallBackReversedConnect(), QJsonValue::fromVariant(), QGeoAreaMonitorInfo::identifier(), javaParcelUuidfromQtUuid(), maybeEncodeTag(), parseReadByTypeCharDiscovery(), QWindowsContext::registerWindowClass(), ServerAcceptanceThread::run(), QBluetoothUuid::streamingOperator(), writeAttribute(), writePrologue(), and QPdfEnginePrivate::writeTail().
|
noexcept |
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.
Definition at line 817 of file quuid.cpp.
References data4, DCE, isNull(), Microsoft, NCS, Reserved, and VarUnknown.
Referenced by version().
|
noexcept |
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.
Definition at line 838 of file quuid.cpp.
References data3, DCE, isNull(), Sha1, Time, variant(), and VerUnknown.
|
related |
Writes the UUID id to the data stream s.
Definition at line 698 of file quuid.cpp.
References QDataStream::BigEndian, QByteArray::data(), i, qToLittleEndian(), Qt::Uninitialized, and QDataStream::WriteFailed.
Returns true
if lhs has the same \l{Variant field} {variant field} as rhs and is lexicographically {not after} rhs. If rhs has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}.
Returns true
if lhs has the same \l{Variant field} {variant field} as rhs and is lexicographically {not before} rhs. If rhs has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}.
|
related |
Reads a UUID from the stream s into id.
Definition at line 734 of file quuid.cpp.
References QDataStream::BigEndian, fromRfc4122(), i, QDataStream::ReadPastEnd, and QDataStream::setStatus().
|
related |
uint QUuid::data1 = 0 |
Definition at line 186 of file quuid.h.
Referenced by _q_uuidToHex(), createGuid(), isNull(), QBluetoothUuid::minimumSize(), QBluetoothUuid::toUInt16(), and QBluetoothUuid::toUInt32().
ushort QUuid::data2 = 0 |
Definition at line 187 of file quuid.h.
Referenced by _q_uuidToHex(), createGuid(), isNull(), QBluetoothUuid::minimumSize(), QBluetoothUuid::toUInt16(), and QBluetoothUuid::toUInt32().
ushort QUuid::data3 = 0 |
Definition at line 188 of file quuid.h.
Referenced by _q_uuidToHex(), createGuid(), isNull(), QBluetoothUuid::minimumSize(), QBluetoothUuid::toUInt16(), QBluetoothUuid::toUInt32(), and version().
uchar QUuid::data4[8] = {} |
Definition at line 189 of file quuid.h.
Referenced by _q_uuidToHex(), createGuid(), isNull(), QBluetoothUuid::minimumSize(), QBluetoothUuid::toUInt16(), QBluetoothUuid::toUInt32(), and variant().