[PyQt] why QCompleter(parent) is TransferBack?

Phil Thompson phil at riverbankcomputing.com
Sat Nov 29 09:33:19 GMT 2014


On 29/11/2014 9:04 am, Yuya Nishihara wrote:
> Hi,
> 
> I'm getting random crash around QCompleter.  The production code is not 
> simple
> but it roughly does:
> 
>     app = QApplication([])
>     window = QMainWindow()
>     lineedit = QLineEdit(window)
>     window.setCentralWidget(lineedit)
>     completer = QCompleter(window)
>     completer.setModel(QDirModel(completer))
>     lineedit.setCompleter(completer)
>     window.show()
>     app.exec_()
> 
> I looked into PyQt source and found that QCompleter(parent) is not 
> annotated
> as TransferThis.
> 
>     QCompleter(QObject *parent /TransferBack/ = 0);
>     QCompleter(QAbstractItemModel *model, QObject *parent 
> /TransferThis/ = 0);
>     QCompleter(const QStringList &list, QObject *parent /TransferThis/ 
> = 0);
> 
> So I've changed the above code as follows, and it seems the crash no 
> longer
> happen.
> 
>      window.setCentralWidget(lineedit)
>     -completer = QCompleter(window)
>     +completer = QCompleter([], window)
>      completer.setModel(QDirModel(completer))
> 
> Is there a reason for setting TransferBack only to QCompleter(parent) ?

No - it's a bug. Your fix is the correct one.

Thanks,
Phil


More information about the PyQt mailing list