[PyQt] Unexpected segfault when using QSortFilterProxyModel with
a QFileDialog
Phil Thompson
phil at riverbankcomputing.com
Wed Oct 7 14:46:05 BST 2009
On Tue, 06 Oct 2009 18:18:32 -0500, Dave Peterson <dpeterson at enthought.com>
wrote:
> I must be doing something brain dead but I'm not sure what. When I
> display a QFileDialog after having set a proxy model, I get a seg fault
> when the QFileDialog tries to save it's state. Here's the top of the
> stacktrace -- perhaps there is enough info here for someone else to be
> able to tell where in the history() method something is going wrong?
>
> Thread 0 Crashed:
> 0 QtGui 0x02498e53 QFileDialog::history()
> const + 115
> 1 QtGui 0x02499115
> QFileDialog::saveState() const + 229
> 2 QtGui 0x024995f7
> QFileDialog::~QFileDialog() + 231
> 3 QtGui.so 0x01a4f137
> sipQFileDialog::~sipQFileDialog() + 89
>
>
> And here's how I'm adding the proxy to the QFileDialog.
>
> dlg = QtGui.QFileDialog(parent, title, default_directory)
> class MyFilterProxy(QtGui.QSortFilterProxyModel):
> def filterAcceptsRow(self, source_row, source_parent):
> logger.debug('MyFilterProxy: %s, %s' % (source_row,
> source_parent))
> return super(MyFilterProxy,
> self).filterAcceptsRow(source_row, source_parent)
> proxy = MyFilterProxy()
> proxy.dynamicSortFilter = True # filter whenever the source data
> changes
> dlg.setProxyModel(proxy)
>
>
> Is the problem that the QFileDialog is taking ownership of the proxy
> instance and thus having memory fights with Python somehow? Or does
> PyQt properly handle that situation? If not, what's the right way to
> create a proxy instance so that this ownership over memory doesn't
happen?
It's a bug. The workaround will be to create the proxy model with a parent
(eg. the dialog).
Phil
More information about the PyQt
mailing list