[Qt-interest] Multiple Objects all having the Same name

Bo Thorsen bo at fioniasoftware.dk
Wed Feb 15 07:33:22 CET 2012


Den 14-02-2012 21:30, Michael Jackson skrev:
> Is it a "Bad Idea" to have multiple objects all have the same Object
> Name? I am writing some code and trying to solve a problem where the
> easiest solution would be to have some of my GUI widgets all have the
> same Object Name. But I am thinking this is a "really bad" idea.

It is probably a bad idea, because

- I can't see a single good reason to do it
- You can't search for objects by name (yes, this is something that is 
actually done for good reasons every now and then)
- Tools like Squish won't work
- You can't do this in designer
- It will confuse other Qt coders, because it's so non-standard

If you don't care about those, then there are no technical reasons 
against it. The object name isn't used for anything important, and it's 
not stored somewhere for global access, or something like it. Actually, 
most QObject instantiations probably have the same object name: The 
empty string.

The only good reason I can find for this is to do something like this:

findChildren<QWidget*>("The Big Name");

But this can be accomplished by not using a name at all, setting a 
property on those you want to handle, and only work on those in the 
loop, or - if it's your own classes - an interface declaration.

If I were your boss, you would have a *very* hard time convincing me 
that this is a good idea, but I'm not saying that it's impossible :-)

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list