pyside / PySide

ATTENTION: This project is deprecated, please refer to PySide2
https://wiki.qt.io/PySide2
GNU Lesser General Public License v2.1
291 stars 66 forks source link

QStringListModel methods inherited from QAbstractListModel said to be private #127

Open nicoddemus opened 9 years ago

nicoddemus commented 9 years ago

Hi there!

First of all thanks for the excellent Qt4 bindings! :smile:

I'm the author of the pytest-qt plugin for pytest, and I'm currently working on creating a Python version of ModelTest.

I'm having some trouble testing a QStringListModel instance because it doesn't seem to provide all the public methods it should as a QAbstractListModel subclass. For example, the docs for QAbstractListModel explicitly say:

The columnCount() function is implemented for interoperability with all kinds of views, but by default informs views that the model contains only one column.

But the snippet below:

def test_string_list_model():
    from PySide import QtCore, QtGui
    model = QtGui.QStringListModel()
    model.setStringList(['hello', 'world'])
    assert model.columnCount(QtCore.QModelIndex()) == 1

Fails with this error:

TypeError: columnCount(const QModelIndex & parent) const is a private method.

I see the same issue with parent() and hasChildren() methods.

The same snippet works fine for PyQt4 and PyQt5.

Is this a known issue? Is there any workaround?

Cheers, :beers:

The-Compiler commented 9 years ago

Did you actually test this with PyQt4/PyQt5 or just assumed it worked because of my model tester code (which uses sip.cast to circumvent this)? Your snippet fails for me with TypeError: QAbstractListModel.columnCount() is a private method with PyQt4/PyQt5 as well. :wink:

Also, those methods definitely are private in Qt, so I don't think PySide is to blame here - except for not having a sip.cast equivalent :wink:

nicoddemus commented 9 years ago

Sorry, you are correct, the snippet does fail in PyQt4 and 5 as well... I got mislead by the documentation, but indeed the C++ header explicitly mark those functions as private. :frown:

I agree this is not a bug but is there any workaround for that problem in Pride?