[PyQt] Python3.4 + PyQt5 QML ListView - Cannot add entries
Phil Thompson
phil at riverbankcomputing.com
Mon Dec 21 18:39:42 GMT 2015
On 21 Dec 2015, at 6:20 pm, Sylvie <iamsylvie at openmailbox.org> wrote:
>
> A small follow-up on this: The second time this function gets called,
>
> print(QQmlProperty.read(resultListObject, "model"))
>
> causes a Segmentation Fault.
>
> On 21/12/15 17:08, Sylvie wrote:
>> Hello everyone,
>>
>> I started a PyQt5 project a few days ago, but am currently stuck at
>> trying to populate a QML ListView from my Python code.
>>
>> Right now, I use findChild to get the ListView with the objectName
>> "resultList" from my QML and pass it along to a function, which works
>> fine. However, the list remains empty after trying to add entries to it.
>> Nothing is displayed, and the count remains 0.
>>
>> I have added some debug print statements to the relevant part my code,
>> in the function which updates the resultList ListView:
>> def updateResultList(self, resultListObject):
>> print(QQmlProperty.read(resultListObject, "count"))
>>
>> print(self.filteredPasswordList)
>>
>> print(QQmlProperty.read(resultListObject, "model"))
>> print(QQmlProperty.write(resultListObject, "model",
>> QStringListModel(self.filteredPasswordList)))
You might want to try keeping a reference to the QStringListModel.
Phil
More information about the PyQt
mailing list