[PyQt] Public QAbstractItemModel methods (wrongfully?) made private in QAbstract(Table|List)Model?

Elvis Stansvik elvstone at gmail.com
Thu Jun 2 09:36:32 BST 2016


Hi all,

>From qabstractitemmodel.sip:

In the declaration of QAbstractTableModel:

private:
    ...
    virtual QModelIndex parent(const QModelIndex &child) const;
    virtual bool hasChildren(const QModelIndex &parent) const;

and in the declaration of QAbstractListModel:

private:
    ...
    virtual QModelIndex parent(const QModelIndex &child) const;
    virtual int columnCount(const QModelIndex &parent) const;
    virtual bool hasChildren(const QModelIndex &parent) const;

But these are all public functions in C++, and part of the public
abstract item model API.

This leads to things like:

[estan at pyret ~]$ cat test.py
from PyQt5.QtCore import QStringListModel
model = QStringListModel()
model.hasChildren()
[estan at pyret ~]$ python test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    model.hasChildren()
TypeError: QAbstractListModel.hasChildren() is a private method

while the same works fine in C++.

I'm not sure how automatic the generation of the SIP files is, but
were these methods perhaps made private by accident because they don't
show up in the Qt documentation under "Reimplemented Public
Functions"? (I think that's a doc bug, and I've brought it up on the
Qt interest@ list).

I think this currently means Python subclasses of these two abstract
classes have to reimplement these methods in order to function
correctly, which is not required in C++.

Best regards,
Elvis


More information about the PyQt mailing list