Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | Related Functions | List of all members
QUuid Class Reference

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

#include <quuid.h>

Public Types

enum  Variant {
  VarUnknown =-1, NCS = 0, DCE = 2, Microsoft = 6,
  Reserved = 7
}
 This enum defines the values used in the Variant field {variant field} of the UUID. More...
 
enum  Version {
  VerUnknown =-1, Time = 1, EmbeddedPOSIX = 2, Name = 3,
  Random = 4
}
 This enum defines the values used in the Version field {version field} of the UUID. More...
 

Public Functions

bool isNull () const
 Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false. More...
 
 operator GUID () const
 Returns a Windows GUID from a QUuid. More...
 
 operator QString () const
 Returns the string representation of the uuid. More...
 
bool operator!= (const QUuid &orig) const
 Returns true if this QUuid and the other QUuid are different; otherwise returns false. More...
 
bool operator!= (const GUID &guid) const
 Returns true if this UUID is not equal to the Windows GUID guid; otherwise returns false. More...
 
bool operator< (const QUuid &other) const
 Returns true if this QUuid has the same Variant field {variant field} as the other QUuid and is lexicographically before the other QUuid. More...
 
QUuidoperator= (const GUID &guid)
 Assigns a Windows guid to a Qt QUuid. More...
 
bool operator== (const QUuid &orig) const
 Returns true if this QUuid and the other QUuid are identical; otherwise returns false. More...
 
bool operator== (const GUID &guid) const
 Returns true if this UUID is equal to the Windows GUID guid; otherwise returns false. More...
 
bool operator> (const QUuid &other) const
 Returns true if this QUuid has the same Variant field {variant field} as the other QUuid and is lexicographically after the other QUuid. More...
 
 QUuid ()
 Creates the null UUID. More...
 
 QUuid (uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)
 Creates a UUID with the value specified by the parameters, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8. More...
 
 QUuid (const QString &)
 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 'x' is a hex digit. More...
 
 QUuid (const char *)
 
 QUuid (const QByteArray &)
 Creates a QUuid object from the QByteArray text, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex digit. More...
 
 QUuid (const GUID &guid)
 Casts a Windows guid to a Qt QUuid. More...
 
QByteArray toByteArray () const
 Returns the binary representation of this QUuid. More...
 
QByteArray toRfc4122 () const
 Returns the binary representation of this QUuid. More...
 
QString toString () const
 Returns the string representation of this QUuid. More...
 
QUuid::Variant variant () const
 Returns the value in the Variant field {variant field} of the UUID. More...
 
QUuid::Version version () const
 Returns the Version field {version field} of the UUID, if the UUID's Variant field {variant field} is QUuid::DCE. More...
 

Static Public Functions

static QUuid createUuid ()
 On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and version QUuid::Random. More...
 
static QUuid fromRfc4122 (const QByteArray &)
 Creates a QUuid object from the binary representation of the UUID given by bytes, as specified by RFC 4122 section 4. More...
 

Public Variables

uint data1
 
ushort data2
 
ushort data3
 
uchar data4 [8]
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &s, const QUuid &id)
 Writes the UUID id to the data stream s. More...
 
QDataStreamoperator>> (QDataStream &s, QUuid &id)
 Reads a UUID from the stream s into id. More...
 

Detailed Description

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

Note
This class or function is reentrant.

Using Universally Unique IDentifiers (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, Globally Unique IDentifiers, but it refers to the same thing.

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 signifcant 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}.

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

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.

msb0 msb1 msb2 msb3

Version

0 0 0 1

Time

0 0 1 0

Embedded POSIX

0 0 1 1

Name

0 1 0 0

Random

The field layouts for the DCE versions listed in the table above are specified in the 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 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 67 of file quuid.h.

Enumerations

◆ Variant

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

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

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

Definition at line 69 of file quuid.h.

69  {
70  VarUnknown =-1,
71  NCS = 0, // 0 - -
72  DCE = 2, // 1 0 -
73  Microsoft = 6, // 1 1 0
74  Reserved = 7 // 1 1 1
75  };

◆ Version

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

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

  • VerUnknown Version is unknown
  • Time Time-based, by using timestamp, clock sequence, and MAC network card address (if available) for the node sections
  • EmbeddedPOSIX DCE Security version, with embedded POSIX UUIDs
  • Name Name-based, by using values from a name for all sections
  • Random Random-based, by using random numbers for all sections
Enumerator
VerUnknown 
Time 
EmbeddedPOSIX 
Name 
Random 

Definition at line 77 of file quuid.h.

77  {
78  VerUnknown =-1,
79  Time = 1, // 0 0 0 1
80  EmbeddedPOSIX = 2, // 0 0 1 0
81  Name = 3, // 0 0 1 1
82  Random = 4 // 0 1 0 0
83  };

Constructors and Destructors

◆ QUuid() [1/6]

QUuid::QUuid ( )
inline

Creates the null UUID.

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

Definition at line 85 of file quuid.h.

Referenced by fromRfc4122(), and QUuid().

86  {
87  data1 = 0;
88  data2 = 0;
89  data3 = 0;
90  for(int i = 0; i < 8; i++)
91  data4[i] = 0;
92  }
uint data1
Definition: quuid.h:179
ushort data3
Definition: quuid.h:181
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ QUuid() [2/6]

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

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 93 of file quuid.h.

94  {
95  data1 = l;
96  data2 = w1;
97  data3 = w2;
98  data4[0] = b1;
99  data4[1] = b2;
100  data4[2] = b3;
101  data4[3] = b4;
102  data4[4] = b5;
103  data4[5] = b6;
104  data4[6] = b7;
105  data4[7] = b8;
106  }
uint data1
Definition: quuid.h:179
ushort data3
Definition: quuid.h:181
QFactoryLoader * l
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ QUuid() [3/6]

QUuid::QUuid ( const QString text)

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 '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.

See also
toString(), QUuid()

Definition at line 335 of file quuid.cpp.

336 {
337  if (text.length() < 36) {
338  *this = QUuid();
339  return;
340  }
341 
342  const ushort *data = reinterpret_cast<const ushort *>(text.unicode());
343 
344  if (*data == '{' && text.length() < 37) {
345  *this = QUuid();
346  return;
347  }
348 
349  if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
350  *this = QUuid();
351  return;
352  }
353 }
uint data1
Definition: quuid.h:179
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar(&d4)[8])
Definition: quuid.cpp:109
ushort data3
Definition: quuid.h:181
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
QUuid()
Creates the null UUID.
Definition: quuid.h:85
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ QUuid() [4/6]

QUuid::QUuid ( const char *  text)
Warning
This function is not part of the public interface.

Definition at line 358 of file quuid.cpp.

359 {
360  if (!text) {
361  *this = QUuid();
362  return;
363  }
364 
366  *this = QUuid();
367  return;
368  }
369 }
uint data1
Definition: quuid.h:179
bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar(&d4)[8])
Definition: quuid.cpp:109
ushort data3
Definition: quuid.h:181
QUuid()
Creates the null UUID.
Definition: quuid.h:85
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180
#define text
Definition: qobjectdefs.h:80

◆ QUuid() [5/6]

QUuid::QUuid ( const QByteArray text)

Creates a QUuid object from the QByteArray text, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where '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 toByteArray() for an explanation of how the five hex fields map to the public data members in QUuid.

Since
4.8
See also
toByteArray(), QUuid()

Definition at line 384 of file quuid.cpp.

385 {
386  if (text.length() < 36) {
387  *this = QUuid();
388  return;
389  }
390 
391  const char *data = text.constData();
392 
393  if (*data == '{' && text.length() < 37) {
394  *this = QUuid();
395  return;
396  }
397 
398  if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
399  *this = QUuid();
400  return;
401  }
402 }
uint data1
Definition: quuid.h:179
bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar(&d4)[8])
Definition: quuid.cpp:109
ushort data3
Definition: quuid.h:181
QUuid()
Creates the null UUID.
Definition: quuid.h:85
static const char * data(const QByteArray &arr)
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ QUuid() [6/6]

QUuid::QUuid ( const GUID guid)
inline

Casts a Windows guid to a Qt QUuid.

Warning
This function is only for Windows platforms.

Definition at line 144 of file quuid.h.

145  {
146  data1 = guid.Data1;
147  data2 = guid.Data2;
148  data3 = guid.Data3;
149  for(int i = 0; i < 8; i++)
150  data4[i] = guid.Data4[i];
151  }
uint data1
Definition: quuid.h:179
ulong Data1
Definition: quuid.h:54
ushort data3
Definition: quuid.h:181
uchar Data4[8]
Definition: quuid.h:57
ushort Data3
Definition: quuid.h:56
uchar data4[8]
Definition: quuid.h:182
ushort Data2
Definition: quuid.h:55
ushort data2
Definition: quuid.h:180

Functions

◆ 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.

If the /dev/urandom device exists, then the numbers used to construct the UUID will be of cryptographic quality, which will make the UUID unique. Otherwise, the numbers of the UUID will be obtained from the local pseudo-random number generator (qrand(), which is seeded by qsrand()) which is usually not of cryptograhic quality, which means that the UUID can't be guaranteed to be unique.

On a Windows platform, a GUID is generated, which almost certainly will be unique, on this or any other system, networked or not.

See also
variant(), version()

Definition at line 897 of file quuid.cpp.

Referenced by QBBRootWindow::createWindowGroup(), QFontEngineFTRawFont::initFromData(), QMainWindowLayout::insertIntoMacToolbar(), operator>(), QAuBucketQWS::QAuBucketQWS(), QNetworkSessionPrivateImpl::QNetworkSessionPrivateImpl(), and QMacPrintEnginePrivate::setPaperSize().

898 {
899  QUuid result;
900  uint *data = &(result.data1);
901 
902 #if defined(Q_OS_UNIX)
903  QFile *devUrandom;
904 # if !defined(QT_BOOTSTRAPPED)
905  devUrandom = devUrandomStorage()->localData();
906  if (!devUrandom) {
907  devUrandom = new QFile(QLatin1String("/dev/urandom"));
909  devUrandomStorage()->setLocalData(devUrandom);
910  }
911 # else
912  QFile file(QLatin1String("/dev/urandom"));
913  devUrandom = &file;
915 # endif
916  enum { AmountToRead = 4 * sizeof(uint) };
917  if (devUrandom->isOpen()
918  && devUrandom->read((char *) data, AmountToRead) == AmountToRead) {
919  // we got what we wanted, nothing more to do
920  ;
921  } else
922 #endif
923  {
924  static const int intbits = sizeof(int)*8;
925  static int randbits = 0;
926  if (!randbits) {
927  int r = 0;
928  int max = RAND_MAX;
929  do { ++r; } while ((max=max>>1));
930  randbits = r;
931  }
932 
933  // Seed the PRNG once per thread with a combination of current time, a
934  // stack address and a serial counter (since thread stack addresses are
935  // re-used).
936 #ifndef QT_BOOTSTRAPPED
937  static QThreadStorage<int *> uuidseed;
938  if (!uuidseed.hasLocalData())
939  {
940  int *pseed = new int;
941  static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
942  qsrand(*pseed = QDateTime::currentDateTime().toTime_t()
943  + quintptr(&pseed)
944  + serial.fetchAndAddRelaxed(1));
945  uuidseed.setLocalData(pseed);
946  }
947 #else
948  static bool seeded = false;
949  if (!seeded)
951  + quintptr(&seeded));
952 #endif
953 
954  int chunks = 16 / sizeof(uint);
955  while (chunks--) {
956  uint randNumber = 0;
957  for (int filled = 0; filled < intbits; filled += randbits)
958  randNumber |= qrand()<<filled;
959 #if defined(Q_OS_SYMBIAN)
960  // Symbian does not have /dev/urandom, so entropy is low.
961  // Add more entropy from the kernel tick count (1ms resolution).
962  // big multipler used to splatter the tick count bits over the whole 32 bits
963  randNumber ^= User::NTickCount() * 0x3b9aca07;
964 #endif
965  *(data+chunks) = randNumber;
966  }
967  }
968 
969  result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
970  result.data3 = (result.data3 & 0x0FFF) | 0x4000; // UV_Random
971 
972  return result;
973 }
uint data1
Definition: quuid.h:179
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_CORE_EXPORT int qrand()
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
ushort data3
Definition: quuid.h:181
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
bool hasLocalData() const
If T is a pointer type, returns true if the calling thread has non-zero data available.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
void setLocalData(T t)
Sets the local data for the calling thread to data.
int fetchAndAddRelaxed(int valueToAdd)
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
Q_CORE_EXPORT void qsrand(uint seed)
uchar data4[8]
Definition: quuid.h:182
The QThreadStorage class provides per-thread data storage.
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67

◆ fromRfc4122()

QUuid QUuid::fromRfc4122 ( const QByteArray bytes)
static

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

Since
4.8

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.

See also
toRfc4122(), QUuid()

Definition at line 421 of file quuid.cpp.

Referenced by operator>>().

422 {
423  if (bytes.isEmpty() || bytes.length() != 16)
424  return QUuid();
425 
426  uint d1;
427  ushort d2, d3;
428  uchar d4[8];
429 
430  const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
431 
433  data += sizeof(quint32);
435  data += sizeof(quint16);
437  data += sizeof(quint16);
438 
439  for (int i = 0; i < 8; ++i) {
440  d4[i] = *(data);
441  data++;
442  }
443 
444  return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]);
445 }
quint32 qFromBigEndian< quint32 >(const uchar *src)
Definition: qendian.h:239
unsigned char uchar
Definition: qglobal.h:994
QUuid()
Creates the null UUID.
Definition: quuid.h:85
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
quint16 qFromBigEndian< quint16 >(const uchar *src)
Definition: qendian.h:249
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
unsigned short ushort
Definition: qglobal.h:995
unsigned int quint32
Definition: qglobal.h:938
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ isNull()

bool QUuid::isNull ( ) const

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

Definition at line 700 of file quuid.cpp.

Referenced by classIDL(), QAxServerBase::internalConnect(), QAxBase::queryInterface(), MetaObjectGenerator::readEnumInfo(), QAxBase::setControl(), variant(), and version().

701 {
702  return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 &&
703  data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
704  data1 == 0 && data2 == 0 && data3 == 0;
705 }
uint data1
Definition: quuid.h:179
ushort data3
Definition: quuid.h:181
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ operator GUID()

QUuid::operator GUID ( ) const
inline

Returns a Windows GUID from a QUuid.

Warning
This function is only for Windows platforms.

Definition at line 159 of file quuid.h.

160  {
161  GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } };
162  return guid;
163  }
uint data1
Definition: quuid.h:179
Definition: quuid.h:52
ushort data3
Definition: quuid.h:181
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ operator QString()

QUuid::operator QString ( ) const
inline

Returns the string representation of the uuid.

See also
toString()

Definition at line 111 of file quuid.h.

111 { return toString(); } // ### Qt5 remove
QString toString() const
Returns the string representation of this QUuid.
Definition: quuid.cpp:512

◆ operator!=() [1/2]

bool QUuid::operator!= ( const QUuid orig) const
inline

Returns true if this QUuid and the other QUuid are different; otherwise returns false.

Definition at line 133 of file quuid.h.

134  {
135  return !(*this == orig);
136  }

◆ operator!=() [2/2]

bool QUuid::operator!= ( const GUID guid) const
inline

Returns true if this UUID is not equal to the Windows GUID guid; otherwise returns false.

Definition at line 170 of file quuid.h.

171  {
172  return !(*this == guid);
173  }

◆ operator<()

bool QUuid::operator< ( const QUuid other) const

Returns true if this QUuid has the same 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 variants.

See also
variant()

Definition at line 807 of file quuid.cpp.

808 {
809  if (variant() != other.variant())
810  return variant() < other.variant();
811 
812  ISLESS(data1, other.data1);
813  ISLESS(data2, other.data2);
814  ISLESS(data3, other.data3);
815  for (int n = 0; n < 8; n++) {
816  ISLESS(data4[n], other.data4[n]);
817  }
818  return false;
819 }
uint data1
Definition: quuid.h:179
QUuid::Variant variant() const
Returns the value in the Variant field {variant field} of the UUID.
Definition: quuid.cpp:756
ushort data3
Definition: quuid.h:181
#define ISLESS(f1, f2)
Definition: quuid.cpp:806
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ operator=()

QUuid & QUuid::operator= ( const GUID guid)
inline

Assigns a Windows guid to a Qt QUuid.

Warning
This function is only for Windows platforms.

Definition at line 153 of file quuid.h.

154  {
155  *this = QUuid(guid);
156  return *this;
157  }
QUuid()
Creates the null UUID.
Definition: quuid.h:85

◆ operator==() [1/2]

bool QUuid::operator== ( const QUuid orig) const
inline

Returns true if this QUuid and the other QUuid are identical; otherwise returns false.

Definition at line 119 of file quuid.h.

120  {
121  uint i;
122  if (data1 != orig.data1 || data2 != orig.data2 ||
123  data3 != orig.data3)
124  return false;
125 
126  for(i = 0; i < 8; i++)
127  if (data4[i] != orig.data4[i])
128  return false;
129 
130  return true;
131  }
uint data1
Definition: quuid.h:179
ushort data3
Definition: quuid.h:181
unsigned int uint
Definition: qglobal.h:996
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ operator==() [2/2]

bool QUuid::operator== ( const GUID guid) const
inline

Returns true if this UUID is equal to the Windows GUID guid; otherwise returns false.

Definition at line 165 of file quuid.h.

166  {
167  return *this == QUuid(guid);
168  }
QUuid()
Creates the null UUID.
Definition: quuid.h:85

◆ operator>()

bool QUuid::operator> ( const QUuid other) const

Returns true if this QUuid has the same 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 variants.

See also
variant()

Definition at line 836 of file quuid.cpp.

837 {
838  if (variant() != other.variant())
839  return variant() > other.variant();
840 
841  ISMORE(data1, other.data1);
842  ISMORE(data2, other.data2);
843  ISMORE(data3, other.data3);
844  for (int n = 0; n < 8; n++) {
845  ISMORE(data4[n], other.data4[n]);
846  }
847  return false;
848 }
uint data1
Definition: quuid.h:179
#define ISMORE(f1, f2)
Definition: quuid.cpp:835
QUuid::Variant variant() const
Returns the value in the Variant field {variant field} of the UUID.
Definition: quuid.cpp:756
ushort data3
Definition: quuid.h:181
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ toByteArray()

QByteArray QUuid::toByteArray ( ) const

Returns the binary representation of this QUuid.

The byte array is formatted as five hex fields separated by '-' and enclosed in curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex digit. From left to right, the five hex fields are obtained from the four public data members in QUuid as follows:

Field #

Source

1

data1

2

data2

3

data3

4

data4[0] .. data4[1]

5

data4[2] .. data4[7]

Since
4.8

Definition at line 558 of file quuid.cpp.

Referenced by QFontEngineFTRawFont::initFromData().

559 {
560  QByteArray result(38, Qt::Uninitialized);
561  char *data = result.data();
562 
563  _q_uuidToHex(data, data1, data2, data3, data4);
564 
565  return result;
566 }
uint data1
Definition: quuid.h:179
void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar(&d4)[8])
Definition: quuid.cpp:91
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
ushort data3
Definition: quuid.h:181
static const char * data(const QByteArray &arr)
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ 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:

Field #

Source

1

data1

2

data2

3

data3

4

data4[0] .. data4[7]

Since
4.8

Definition at line 601 of file quuid.cpp.

602 {
603  // we know how many bytes a UUID has, I hope :)
604  QByteArray bytes(16, Qt::Uninitialized);
605  uchar *data = reinterpret_cast<uchar*>(bytes.data());
606 
607  qToBigEndian(data1, data);
608  data += sizeof(quint32);
609  qToBigEndian(data2, data);
610  data += sizeof(quint16);
611  qToBigEndian(data3, data);
612  data += sizeof(quint16);
613 
614  for (int i = 0; i < 8; ++i) {
615  *(data) = data4[i];
616  data++;
617  }
618 
619  return bytes;
620 }
uint data1
Definition: quuid.h:179
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
ushort data3
Definition: quuid.h:181
unsigned char uchar
Definition: qglobal.h:994
T qToBigEndian(T source)
Definition: qendian.h:337
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int quint32
Definition: qglobal.h:938
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ toString()

QString QUuid::toString ( ) const

Returns the string representation of this QUuid.

The string is formatted as five hex fields separated by '-' and enclosed in curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex digit. From left to right, the five hex fields are obtained from the four public data members in QUuid as follows:

Field #

Source

1

data1

2

data2

3

data3

4

data4[0] .. data4[1]

5

data4[2] .. data4[7]

Definition at line 512 of file quuid.cpp.

Referenced by classIDL(), QBBRootWindow::createWindowGroup(), DumpIDL(), MetaObjectGenerator::readClassInfo(), MetaObjectGenerator::readEventInfo(), MetaObjectGenerator::readInterfaceInfo(), QAxBase::setControl(), and UpdateRegistry().

513 {
514  QString result(38, Qt::Uninitialized);
515  ushort *data = (ushort *)result.unicode();
516 
517  _q_uuidToHex(data, data1, data2, data3, data4);
518 
519  return result;
520 }
uint data1
Definition: quuid.h:179
void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar(&d4)[8])
Definition: quuid.cpp:91
The QString class provides a Unicode character string.
Definition: qstring.h:83
ushort data3
Definition: quuid.h:181
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
uchar data4[8]
Definition: quuid.h:182
ushort data2
Definition: quuid.h:180

◆ variant()

QUuid::Variant QUuid::variant ( ) const

Returns the value in the 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 756 of file quuid.cpp.

Referenced by operator<(), operator>(), and version().

757 {
758  if (isNull())
759  return VarUnknown;
760  // Check the 3 MSB of data4[0]
761  if ((data4[0] & 0x80) == 0x00) return NCS;
762  else if ((data4[0] & 0xC0) == 0x80) return DCE;
763  else if ((data4[0] & 0xE0) == 0xC0) return Microsoft;
764  else if ((data4[0] & 0xE0) == 0xE0) return Reserved;
765  return VarUnknown;
766 }
bool isNull() const
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false...
Definition: quuid.cpp:700
uchar data4[8]
Definition: quuid.h:182

◆ version()

QUuid::Version QUuid::version ( ) const

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

Otherwise it returns QUuid::VerUnknown.

See also
variant()

Definition at line 780 of file quuid.cpp.

781 {
782  // Check the 4 MSB of data3
783  Version ver = (Version)(data3>>12);
784  if (isNull()
785  || (variant() != DCE)
786  || ver < Time
787  || ver > Random)
788  return VerUnknown;
789  return ver;
790 }
Version
This enum defines the values used in the Version field {version field} of the UUID.
Definition: quuid.h:77
QUuid::Variant variant() const
Returns the value in the Variant field {variant field} of the UUID.
Definition: quuid.cpp:756
bool isNull() const
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false...
Definition: quuid.cpp:700
ushort data3
Definition: quuid.h:181

Friends and Related Functions

◆ operator<<()

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

Writes the UUID id to the data stream s.

Definition at line 630 of file quuid.cpp.

631 {
632  QByteArray bytes;
633  if (s.byteOrder() == QDataStream::BigEndian) {
634  bytes = id.toRfc4122();
635  } else {
636  // we know how many bytes a UUID has, I hope :)
637  bytes = QByteArray(16, Qt::Uninitialized);
638  uchar *data = reinterpret_cast<uchar*>(bytes.data());
639 
640  qToLittleEndian(id.data1, data);
641  data += sizeof(quint32);
642  qToLittleEndian(id.data2, data);
643  data += sizeof(quint16);
644  qToLittleEndian(id.data3, data);
645  data += sizeof(quint16);
646 
647  for (int i = 0; i < 8; ++i) {
648  *(data) = id.data4[i];
649  data++;
650  }
651  }
652 
653  if (s.writeRawData(bytes.data(), 16) != 16) {
655  }
656  return s;
657 }
uint data1
Definition: quuid.h:179
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
ByteOrder byteOrder() const
Returns the current byte order setting – either BigEndian or LittleEndian.
Definition: qdatastream.h:209
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setStatus(Status status)
Sets the status of the data stream to the status given.
ushort data3
Definition: quuid.h:181
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int quint32
Definition: qglobal.h:938
uchar data4[8]
Definition: quuid.h:182
T qToLittleEndian(T source)
Definition: qendian.h:341
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
ushort data2
Definition: quuid.h:180

◆ operator>>()

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

Reads a UUID from the stream s into id.

Definition at line 666 of file quuid.cpp.

667 {
668  QByteArray bytes(16, Qt::Uninitialized);
669  if (s.readRawData(bytes.data(), 16) != 16) {
671  return s;
672  }
673 
674  if (s.byteOrder() == QDataStream::BigEndian) {
675  id = QUuid::fromRfc4122(bytes);
676  } else {
677  const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
678 
679  id.data1 = qFromLittleEndian<quint32>(data);
680  data += sizeof(quint32);
681  id.data2 = qFromLittleEndian<quint16>(data);
682  data += sizeof(quint16);
683  id.data3 = qFromLittleEndian<quint16>(data);
684  data += sizeof(quint16);
685 
686  for (int i = 0; i < 8; ++i) {
687  id.data4[i] = *(data);
688  data++;
689  }
690  }
691 
692  return s;
693 }
quint16 qFromLittleEndian< quint16 >(const uchar *src)
Definition: qendian.h:157
ByteOrder byteOrder() const
Returns the current byte order setting – either BigEndian or LittleEndian.
Definition: qdatastream.h:209
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setStatus(Status status)
Sets the status of the data stream to the status given.
unsigned char uchar
Definition: qglobal.h:994
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
unsigned short quint16
Definition: qglobal.h:936
quint32 qFromLittleEndian< quint32 >(const uchar *src)
Definition: qendian.h:148
static const char * data(const QByteArray &arr)
unsigned int quint32
Definition: qglobal.h:938
static QUuid fromRfc4122(const QByteArray &)
Creates a QUuid object from the binary representation of the UUID given by bytes, as specified by RFC...
Definition: quuid.cpp:421

Properties

◆ data1

uint QUuid::data1

◆ data2

ushort QUuid::data2

◆ data3

ushort QUuid::data3

◆ data4

uchar QUuid::data4[8]

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