[Qt-interest] Multiple Objects all having the Same name
Andreas Pakulat
apaku at gmx.de
Wed Feb 15 10:51:50 CET 2012
On 15.02.12 08:41:48, Bo Thorsen wrote:
> Den 15-02-2012 08:37, Andreas Pakulat skrev:
> >On 15.02.12 07:33:22, Bo Thorsen wrote:
> >>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
> >[...]
> >>- Tools like Squish won't work
> >
> >Thats wrong at least for Squish. While Squish does use the objectName
> >for identification purposes its not the only property of an object it
> >uses and hence its not necessarily going to fail in the case of two
> >objects having the same name. There are cases of course where the wrong
> >object could be found if not only the object name but also all other
> >properties and all containers are the same (i.e. the two widgets are in
> >the same container widget and have the same properties - including the
> >type).
>
> No, it's not wrong. If you have unique object names, Squish will
> work for sure, even when you rearrange the object tree, change
> properties, etc.
When you re-arrange the object tree you can also get names with just
type and objectname to fail since Squish does not search the complete
QObject tree using findChildren() or the like. At least not for Qt4. It
walks the object tree according to the hierarchy stored in the name, if
you change the hierarchy too much Squish will fail to find the object
since the parents will at some point not match anymore.
I agree though that some cases of object names are really hard to
destroy, like {type='QPushButton' name='ClickMe'
window={type='QMainWindow' name='Main'}}. Here you'd have to move the
button to a completely different top-level window or change to another
non-QMainWindow subclass to break it, but its still possible.
Also objectname itself might change over time.
Anyway, the point was that non-unique object names will not break Squish
in general. You may consider it useless afterwards but thats certainly
not the opinion of all Squish users.
Andreas
More information about the Qt-interest-old
mailing list