PDA

View Full Version : Unique Id of Qwidget



alex1
27th September 2011, 14:44
I want to do QHash which will be used key (some widget id)
how can I get a certain individual Id of qwidget for use it as a unique key?
objectname can not be used because QHash will contain widgets from different classes,
meaning they can be the widgets with the same name....

gareth
27th September 2011, 22:59
How about the pointer address (cast to an appropriately-sized integer, i.e. qint32 or qint64 depending on your platform)? For widgets within a process, this will be unique for each instance.

ChrisW67
28th September 2011, 03:28
objectname can not be used because QHash will contain widgets from different classes,
meaning they can be the widgets with the same name....
Only if you program it that way. Having each class set its object name to a UUID or QString("ClassName%1).arg(staticSequenceVariable++) in its constructor would be another approach.

alex1
1st October 2011, 10:00
Thanks very much.

But, what can I do to not be dependent on the platform?
QVariant do not want to use,
ifndef / endef also do not want to use.

wysota
1st October 2011, 15:27
I'd go for pointers or a unique number generator.

alex1
5th October 2011, 08:28
Thanks,
But a unique number will not work because key must be part of QWidget
So I need to use :{ ,
have other ideas?

FelixB
5th October 2011, 08:48
then you have to use the pointer adress.

btw, why must the key be part of QWidget?

wysota
5th October 2011, 10:56
Thanks,
But a unique number will not work because key must be part of QWidget

I don't see your point. It works quite fine for Qt Creator so I don't see why wouldn't it work for you.