QUuid
#include <QUuid>
Public Types
enum | StringFormat { WithBraces, WithoutBraces, Id128 } |
enum | Variant { VarUnknown, NCS, DCE, Microsoft, Reserved } |
enum | Version { VerUnknown, Time, EmbeddedPOSIX, Name, ..., Sha1 } |
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(const QString &text) | |
QUuid(const QByteArray &text) | |
QUuid(const GUID &guid) | |
bool | isNull() const |
QByteArray | toByteArray() const |
QByteArray | toByteArray(QUuid::StringFormat mode) const |
CFUUIDRef | toCFUUID() const |
NSUUID * | toNSUUID() const |
QByteArray | toRfc4122() const |
QString | toString() const |
QString | toString(QUuid::StringFormat mode) const |
QUuid::Variant | variant() const |
QUuid::Version | version() const |
GUID | operator GUID() const |
bool | operator!=(const QUuid &other) const |
bool | operator!=(const GUID &guid) const |
bool | operator<(const QUuid &other) const |
QUuid & | operator=(const GUID &guid) |
bool | operator==(const QUuid &other) const |
bool | operator==(const GUID &guid) const |
bool | operator>(const QUuid &other) const |
Static Public Members
QUuid | createUuid() |
QUuid | createUuidV3(const QUuid &ns, const QByteArray &baseData) |
QUuid | createUuidV3(const QUuid &ns, const QString &baseData) |
QUuid | createUuidV5(const QUuid &ns, const QByteArray &baseData) |
QUuid | createUuidV5(const QUuid &ns, const QString &baseData) |
QUuid | fromCFUUID(CFUUIDRef uuid) |
QUuid | fromNSUUID(const NSUUID *uuid) |
QUuid | fromRfc4122(const QByteArray &bytes) |
QUuid | fromString(QStringView text) |
QUuid | fromString(QLatin1String text) |
Related Non-Members
uint | qHash(const QUuid &uuid, uint seed = 0) |
QDataStream & | operator<<(QDataStream &s, const QUuid &id) |
QDebug | operator<<(QDebug dbg, const QUuid &id) |
bool | operator<=(const QUuid &lhs, const QUuid &rhs) |
bool | operator>=(const QUuid &lhs, const QUuid &rhs) |
QDataStream & | operator>>(QDataStream &s, QUuid &id) |
详细说明
QUuid类存储一个通用唯一标识符(UUID)。
使用通用唯一标识符(UUID)是在分布式计算环境中唯一标识实体的标准方法。UUID是由某种算法生成的16字节(128位)数字,旨在保证UUID在使用它的分布式计算环境中是唯一的。缩写GUID通常被用来代替全局唯一标识符,但它指的是同一件事。
实际上,GUID是UUID的一种变体。多种变体正在使用中。每个UUID都包含一个位字段,该字段指定它是哪种类型的UUID(变体)。调用variant()可以发现QUuid实例包含哪种UUID类型。它提取16个字节中字节8的三个最高有效位。在QUuid中,字节8是QUuid::data4[0]。如果使用接受所有数值作为参数的构造函数创建QUuid的实例,请使用下表设置参数b1的三个最高有效位,该参数变为QUuid::data4[0],并在其三个最有效位中包含变量字段。在表中,“x”表示不在乎。
msb0 | msb1 | msb2 | Variant |
---|---|---|---|
0 | x | x | NCS (Network Computing System) |
1 | 0 | x | DCE (Distributed Computing Environment) |
1 | 1 | 0 | Microsoft (GUID) |
1 | 1 | 1 | Reserved for future expansion |
如果variant()返回QUuid::DCE,则UUID在QUuid::data3的四个最高有效位中也包含一个版本字段,您可以调用version()来发现您的QUuid包含哪个版本。如果使用接受所有数值作为参数的构造函数创建QUuid的实例,请使用下表设置参数w2的四个最高有效位,该参数将变为QUuid::data3,并在其四个最有效位中包含版本字段。
msb0 | msb1 | msb2 | msb3 | Version |
---|---|---|---|---|
0 | 0 | 0 | 1 | Time |
0 | 0 | 1 | 0 | Embedded POSIX |
0 | 0 | 1 | 1 | Md5(Name) |
0 | 1 | 0 | 0 | Random |
0 | 1 | 0 | 1 | Sha1 |
上表中列出的DCE版本的字段布局在网络工作组UUID规范中指定。
大多数平台都提供了生成新UUID的工具,例如uuidgen和guidgen。您也可以使用createUuid()。createUuid()生成的UUID属于随机类型。它们的QUuid::Version位设置为QUuid::Random,而它们的QUuid::Variant位设置为Quid::DCE。UUID的其余部分由随机数组成。从理论上讲,这意味着createUuid()生成的UUID不唯一的可能性很小。但这是一个非常小的机会。
UUID可以由数值或字符串构造,也可以使用静态createUuid()函数。可以使用toString()将它们转换为字符串。UUID有一个variant()和一个version(),null UUID从isNull()返回true。
toString(StringFormat)使用此枚举来控制字符串表示形式的格式。可能的值为:
Constant | Value | Description |
---|---|---|
QUuid::WithBraces |
0 |
The default, toString() will return five hex fields, separated by dashes and surrounded by braces. Example: {00000000-0000-0000-0000-000000000000}. |
QUuid::WithoutBraces |
1 |
Only the five dash-separated fields, without the braces. Example: 00000000-0000-0000-0000-000000000000. |
QUuid::Id128 |
3 |
Only the hex digits, without braces or dashes. Note that QUuid cannot parse this back again as input. |
enum QUuid::Variant
This enum defines the values used in the variant field of the UUID. The value in the variant field determines the layout of the 128-bit value.
Constant | Value | Description |
---|---|---|
QUuid::VarUnknown |
-1 |
Variant is unknown |
QUuid::NCS |
0 |
Reserved for NCS (Network Computing System) backward compatibility |
QUuid::DCE |
2 |
Distributed Computing Environment, the scheme used by QUuid |
QUuid::Microsoft |
6 |
Reserved for Microsoft backward compatibility (GUID) |
QUuid::Reserved |
7 |
Reserved for future definition |
enum QUuid::Version
This enum defines the values used in the version field of the UUID. The version field is meaningful only if the value in the variant field is QUuid::DCE.
Constant | Value | Description |
---|---|---|
QUuid::VerUnknown |
-1 |
Version is unknown |
QUuid::Time |
1 |
Time-based, by using timestamp, clock sequence, and MAC network card address (if available) for the node sections |
QUuid::EmbeddedPOSIX |
2 |
DCE Security version, with embedded POSIX UUIDs |
QUuid::Name |
Md5 |
Name-based, by using values from a name for all sections |
QUuid::Md5 |
3 |
Alias for Name |
QUuid::Random |
4 |
Random-based, by using random numbers for all sections |
QUuid::Sha1 |
5 |
Member Function Documentation
################################
标签:const,UUID,bool,QUuid,operator,GUID From: https://www.cnblogs.com/herd/p/17498388.html