[PyQt] causes self to be owned by Qt instead of PyQt ???
Andreas Pakulat
apaku at gmx.de
Thu Apr 2 23:01:15 BST 2015
Hi Phil,
On Thu, Apr 2, 2015 at 11:11 PM, Phil Thompson <phil at riverbankcomputing.com>
wrote:
> On 02/04/2015 7:37 pm, Baz Walter wrote:
>
>> On 02/04/15 18:33, Phil Thompson wrote:
>>
>>> On 02/04/2015 5:38 pm, Baz Walter wrote:
>>>
>>>> On 02/04/15 17:18, Andreas Pakulat wrote:
>>>>
>>>> QAbstractItemModel.parent(QModelIndex) overloads QObject.parent(), so
>>>> it is a bug in PyQt4/5 that it doesn't support the latter.
>>>>
>>>
>>> Eh? The QAbstractItemModel parent() hides the QObject parent().
>>>
>>
>> No, it shouldn't do. A QAbstractItemModel is a QObject. It takes
>> another QObject as its parent, not a QModelIndex:
>>
>> from PyQt4 import QtCore, QtGui
>>>>> app = QtGui.QApplication([])
>>>>> model = QtGui.QStandardItemModel(app)
>>>>> model.parent()
>>>>>
>>>> <PyQt4.QtGui.QApplication object at 0x7f397aae0c18>
>>
>>> model.parent(QtCore.QModelIndex())
>>>>>
>>>> <PyQt4.QtCore.QModelIndex object at 0x7f3975078358>
>>
>> QAbstractItemModel::parent(QModelIndex) is virtual, but
>> QObject::parent() isn't, so it cannot not be overridden.
>>
>
> So the attached C++ code should compile?
Not without a fix for qfilesystemmodel.h. qabstractitemmodel.h as well as
qstandarditemmodel.h (and probably other qaim subclasses in qt) explicitly
'reuse' QObject::parent using something like:
#ifdef Q_NO_USING_KEYWORD
inline QObject *parent() const { return QObject::parent(); }
#else
using QObject::parent;
#endif
For qfilesystemmodel.h this is missing and hence one cannot call
QObject::parent() with a pointer or instance of it.
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150403/e8aae9c4/attachment.html>
More information about the PyQt
mailing list