PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 536 - FEATURE: Add property to QObject that exposes is C++ reference is still valid
: FEATURE: Add property to QObject that exposes is C++ reference is still valid
Status: CLOSED DUPLICATE of bug 902
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: All All
: P4 enhancement
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-12-07 18:08 EET by David Martínez Martí
Modified: 2011-08-23 00:37 EEST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Martínez Martí 2010-12-07 18:08:06 EET
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.
Comment 1 Matti Airas 2010-12-08 05:48:50 EET
Hi,

Thanks for the nice idea!

Since this is an API feature, I forwarded the proposal to the mailing list for
discussion. If the idea gains support, a mini-PSEP (PySide Enhancement
Proposal) could be made for it to precisely define the syntax and semantics for
implementation.

I'm marking this P4 WAITING (i.e., pending opinions on the mailing list).
Comment 2 Thomas Perl 2010-12-08 06:50:20 EET
Mailing list thread of the discussion:

http://lists.openbossa.org/pipermail/pyside/2010-December/001572.html

My opinion: Make it available, but outside the "normal" APIs (i.e. not as
property to QObject, but as a special function) and maybe only in debug builds.
Comment 3 Hugo Parente Lima 2011-08-03 17:28:48 EEST
Marking this as duplicate of bug #902, this bug is younger than bug 902, but
the description is less complete.

Regards

*** This bug has been marked as a duplicate of bug 902 ***
Comment 4 renato filho 2011-08-23 00:37:20 EEST
Release PySide 1.0.6