On Monday 03 January 2011 04:14:41 Thomas Perl wrote: > 2011/1/2 Algis Kabaila <akaba...@pcug.org.au>: > > To put it briefly, if it is a good practice to use > > setObjectName on all objects, I would like to know and > > tell others to do that. > > Check out the documentation about the "objectName" property: > > http://doc.qt.nokia.com/latest/qobject.html#objectName-prop > > It turns out that you can use "findChild" to search for > children by name: > > http://doc.qt.nokia.com/latest/qobject.html#findChild > > So if you only have a reference to your top-level window, you > could get a reference to the child with the specific name > using the findChild method on the top-level window. > > My guess would be that for auto-generated code (from .ui > files), you can just leave it in (and maybe take advantage > of findChild if you want to get a specific object), and for > code that you write yourself, you would only set an object > name if you want to use findChild later to get a reference > to that object from a higher-level (direct or indirect > parent) widget/object. > > This could also be useful if you set the same name on > multiple widgets and then interate over all those widgets > with findChildren, e.g. you have several buttons sprinkled > throughout one window, and all "belong" together somehow. If > you name them all "fooButton", you could use "for button in > window.findChildren('fooButton'): ..." to iterate over all > buttons. I haven't used this myself, so maybe there are some > other more obvious use cases for object names :) > > HTH. > Thomas
Thomas, Thanks for the contribution. I did have a look that the reference. All I can deduce is that potentially the x in x = setObjectName(<object>) might be useful in tracing those elusive "segmentation faults" when the destruction of the objects by the trash collector is out of sync.. With my current confusion it would seem reasonable to leave those statements in a commented out form. It is a kind of compromise - the statement is not used, so it should not be there, so whe make it inactive. But perhaps the statement might be useful in some circumstances, so its 'image' is left in. There are quite a few of these inactive statements in a small example - would you care to look a it: http://developer.qt.nokia.com/wiki/PySideSimplicissimusCombineAllIn1 How does it strike you? Al. -- Algis http://akabaila.pcug.org.au _______________________________________________ PySide mailing list PySide@lists.openbossa.org http://lists.openbossa.org/listinfo/pyside