[PyQt] Public QAbstractItemModel methods (wrongfully?) made private in QAbstract(Table|List)Model?
Florian Bruhin
me at the-compiler.org
Thu Jun 2 10:53:30 BST 2016
* Elvis Stansvik <elvstone at gmail.com> [2016-06-02 10:36:32 +0200]:
> 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.
No, they are private in C++ as well:
https://github.com/qtproject/qtbase/blob/dev/src/corelib/itemmodels/qabstractitemmodel.h#L381-L384
https://github.com/qtproject/qtbase/blob/dev/src/corelib/itemmodels/qabstractitemmodel.h#L407-L411
I guess the rationale is that it makes no sense to ask e.g. how many
columns a list has?
> 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++.
It does not for me:
test.cpp: In function 'int main(int, char**)':
test.cpp:17:25: error: 'virtual bool QAbstractListModel::hasChildren(const QModelIndex&) const' is private within this context
qsl->hasChildren(idx);
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160602/36542437/attachment.sig>
More information about the PyQt
mailing list