Issue
Simple question as in the title - if I call setObjectName()
on an object, does it have to be unique, or is it just recommended because of convention? I've subclassed QLabel
, and want to automatically give the objects created a name; if this is a bad idea, I'll find some way of setting a random unique name. (I'm actually using PyQt, but this shouldn't influence the answer!)
Update
In response to the 2 answers so far (which I should have predicted!), I want to do this so that I can ignore all instances of my subclass. Calling findChildren(QLabel)
cascades so that all subclasses of QLabel
are also found - if I use the same object name for all my subclassed objects, then I can just regex in the 2nd argument of findChildren()
so that I ignore them
Solution
If you look at the documentation for QObject, you can see that it states: -
This property holds the name of this object. You can find an object by name (and type) using findChild(). You can find a set of objects with findChildren().
Looking at findChildren(), it states: -
Returns all children of this object with the given name that can be cast to type T...
So, clearly it can be seen that multiple objects can have the same name.
Answered By - TheDarkKnight
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.