Hi list,

David Martínez Martí submitted the following to our Bugzilla as an enhancement request (bug 536). Since the proposal is essentially an API feature request, I thought I'd better forward it to the mailing list for discussion. To me the proposal sounds like it could be useful in some situations, but I readily admit I'm not proficient enough to properly judge its merits.

--8<----8<----8<----8<----8<----8<----8<----8<----8<--

Some QtGui functions handles the proper destruction of the object when some conditions are met. For example, QMainWindow.setCentralWidget may destroy the old widget, QTabWidget.removeTab may destroy the old widget in the tab. Also, an (possible, but improbable) error in the garbage collector of PySide may destroy a widget while in python we hold a reference.

To track these problems and avoid calling methods for objects that no longer exist may be useful a property exposing if the C++ pointer is still valid.

For example, if the reference to self.layout (say, a layout in a QMainWindow, where self is the instance of QMainWindow) could have been destroyed, in python we could write:

try:
    self.layout.addWidget(self.newwidget)
except RuntimeError:
    # propably self.layout was destroyed before!
    # we could create a new one instead.
    self.layout = new QVBoxLayout(self.frame)
    # and re-add the widget:
    self.layout.addWidget(self.newwidget)


But it we had a property for that, like QObject::isValid(), we could simplify a lot this logic:

if not self.layout.isValid(): self.layout = new QVBoxLayout(self.frame)
self.layout.addWidget(self.newwidget)

Of course this is not the right way to code, the developer should code in such a way that this "isValid()" function would be useless.. but anyway this will be very helpful to avoid bugs, or for some debugging purposes.

--8<----8<----8<----8<----8<----8<----8<----8<----8<--

Cheers,

ma.
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to