[PySide] QStringListModel.stringList returns copy of list.
robbert
superslimme at netscape.net
Wed Oct 22 20:47:41 CEST 2014
Hi,
I'm trying to dynamically add words to a QStringListModel, for the use
with a QCompleter.
It seems that you cannot add an item to the List returned from
stringList. The List returned by stringList seems to be a copy,
but the documentation suggests otherwise:
stringList(): "Returns the string list used by the model to store data." [1]
Is this the correct behavior?
Here a snippet to show the effect.
from PySide.QtGui import QStringListModel
model = QStringListModel(["A", "B", "C"])
print model.stringList()
model.stringList().append("D")
print model.stringList()
myStringList = model.stringList()
myStringList.append("E")
model.setStringList(myStringList)
print model.stringList()
Returns:
[u'A', u'B', u'C']
[u'A', u'B', u'C']
[u'A', u'B', u'C', u'E']
I would expect "D" to be added to list.
Btw, the example given in the documentation doesn't work. The following
line works, and should do the same.
model = QStringListModel(["a", "b", "c"])
Kind regards,
Robbert
[1]
http://pyside.github.io/docs/pyside/PySide/QtGui/QStringListModel.html#PySide.QtGui.PySide.QtGui.QStringListModel.stringList
More information about the PySide
mailing list