[PySide] QStringListModel.stringList returns copy of list.

robbert superslimme at netscape.net
Wed Oct 22 20:47:41 CEST 2014


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()


print model.stringList()

myStringList = model.stringList()



print model.stringList()


[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,



More information about the PySide mailing list