[Qt-interest] tracking uniqueness
Eirik Ulvik
eiriku at simsurgery.com
Mon Apr 26 08:59:01 CEST 2010
Den 24.04.2010 12:36, skrev Oliver Heins:
> Thiago Macieira <thiago at kde.org> writes:
>
>> Em Sábado 24. Abril 2010, às 10.10.29, Oliver Heins escreveu:
>>> Andreas Pakulat <apaku at gmx.de> writes:
>>>> You seem to have a bit of misconception about this. There is no Editor
>>>> instance in your code. All you do is declare a class and a nested class,
>>>> both can be used without an instance of the other as far as your example
>>>> goes. In particular, this:
>>>>
>>>> class Editor
>>>> {
>>>>
>>>> public:
>>>> class Token
>>>> {
>>>> };
>>>>
>>>> };
>>>>
>>>> Editor::Token t;
>>>>
>>>> is perfectly valid compiling code. And there's no instance of Editor
>>>> generated here, there's only a single instance of Token.
>>>
>>> So it's not possible in C++ to describe the idea: »Every instance of
>>> Token is held by an instance of Editor«?
>>
>> Of course it is.
>>
>> The counter is per editor, right? So it's a property of the editor.
>
> Yes, but I have to hand over the id exlicitely. I hoped to do something
> like this:
>
> class Editor
> {
> class Token
> {
> public:
> Token () : uniqId(++id_) { }
> private:
> quint32 uniqId;
> }
>
> quint32 id_;
> };
>
> or to make id_ somehow static only to the instance of Editor.
>
> But both doesn't work. Instead, I have to pass id_ explicitely in every
> constructor call:
>
> Token(quint32 &id_) : uniqId(++id_) { }
>
> Best regards,
> olli
I might be missing something here, but your problem seem related to
making the id unique ie. doing uniqId++ or something like that in a
consistent manner. What about just putting a QUuid
(http://doc.trolltech.com/4.6/quuid.html) member variable in your editor
class and instantiate it in the constructor? This would ensure that you
have a unique identifier for every editor in the simplest way IMO. The
only trouble I see is that QUuid's are not easy to work with if you need
the id to be human-readable.
Regards,
Eirik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100426/1df50e54/attachment.bin
More information about the Qt-interest-old
mailing list