Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QUniqueIdGenerator Class Reference
[QtBaseModule]

The QUniqueIdGenerator class provides a generator of unique identifiers. More...

    #include <QUniqueIdGenerator>

Public Functions

Static Public Members


Detailed Description

The QUniqueIdGenerator class provides a generator of unique identifiers.

The unique identifiers that are generated are 32 bits and are unique within the device they are created upon. If you require an identifier that is unique across multiple devices use QUuid instead.

The identifiers are are generated with a QUuid context identifier and an index. The context should be generated with a program such as uuidgen and represent the data store or context within which the identifier is generated. For example SQL and SIM card storage for QContacts each have their own context. The context is mapped to a 8 bit value allowing for 255 contexts for a single device.

The usual approach to constructing QUniqueIds is:

    QUniqueIdGenerator generator(myContext);
    id = generator.createId();

QUniqueIdGenerator is suitable in cases where you need to generate an average of 100 identifiers a day or less and require a low number of bits when stored. If your program is likely to need more than 100 unique identifiers a day or does not benefit from the low 32bit storage size it is recommended you look at another type of unique id such as QUuid.


Member Function Documentation

QUniqueIdGenerator::QUniqueIdGenerator ( const QUuid & context )

Constructs a QUniqueIdGenerator with the given context. It is recommended that the context be hard coded into your application.

Example:

    QUniqueIdGenerator(QUUid("bd668b78-d892-4345-b0a3-77502d684f06"));

You can generate the context string using the uuidgen program. As there are only 255 available contexts, you should generate the context when developing your application, not as part of the application's execution.

QUniqueIdGenerator::QUniqueIdGenerator ( const QUniqueIdGenerator & other )

Constructs a copy of other.

QUniqueIdGenerator::~QUniqueIdGenerator ()

Destroys the QUniqueIdGenerator.

QUniqueId QUniqueIdGenerator::constructTemporaryId ( uint index )   [static]

Returns an identifier that is valid only within a single application with the given index component. This identifier should not be shared or persisted between different applications or different executions of the same application. This function does not ensure the constructed identifier is not in conflict with past or future QUniqueId objects.

This function is not threadsafe.

QUniqueId QUniqueIdGenerator::constructUniqueId ( uint index )

Returns a identifier with the given index component. Does not ensure the constructed identifier is not in conflict with past or future QUniqueId objects.

See also createUniqueId().

QUniqueId QUniqueIdGenerator::createTemporaryId ()   [static]

Returns a identifier that is valid only within a single application. This identifier should not be shared or persisted between different applications or different executions of the same application.

This function is not threadsafe.

QUniqueId QUniqueIdGenerator::createUniqueId ()

Returns an identifier with the same context component as the generator and an index component that is unique against other identifiers generated with this function for the same context and device.

See also constructUniqueId().

bool QUniqueIdGenerator::isValid () const

Returns true if the generator is valid and can be used to create or construct unique identifers. Otherwise returns false.

This function should only be needed during debugging as only a generator constructed using null QUuids will be invalid.

uint QUniqueIdGenerator::mappedContext ( const QUuid & context )   [static]

Returns a locally mapped integer value for context suitable for efficiently checking if a QUniqueId was generated from an equivalent QUniqueIdGenerator.

See also QUniqueId::mappedContext().


Copyright © 2009 Nokia Trademarks
Qt Extended 4.4.3