[PyQt] PyQt5.8.2 Qml GridView TypeError: unable to convert a Python 'MyListModel' object to a C++ 'QAbstractListModel*' instance
Phil Thompson
phil at riverbankcomputing.com
Wed Apr 5 00:18:50 BST 2017
On 3 Apr 2017, at 2:46 am, chunyisong at sina.com wrote:
>
>
> Hello everyone,
>
>
> I encountered an “TypeError” that my python subclass listmodel of QAbsctactListModel object can not be recognized as a C++ 'QAbstractListModel*' instance!
> In order to simplify the problem, I simplified the project code to a demo attachments and also listed below the contents of the email.
> The demo has two python subclass of QAbsctactListModel :RuleModel and RuleGroupModel;RuleModel instance will be a role of RuleGroupModel
> to provide rules of a group.I test it with PyQt5.7.1 and PyQt5.8.2 ,both encountered the same Type Error which crashed the app is:
> " TypeError: invalid result from RuleGroupModel.data(), unable to convert a Python 'RuleModel' object to a C++ 'QAbstractListModel*' instance ".
> But when the count of changing model of Qml GridView "many times" ,the error raised.I am confused thar the error do not occure within a few times such as 5 or more times;
> The error will surely occure after more times of rule model change.To reproduce the error I use a Timer in the Test.qml to simulate many times of user actions.
> Any advice to the e
I can reproduce the problem. The failure happend between trigger 107 and trigger 108. At that time the C++ instances of the RuleModel objects are being deleted via calls to deleteLater() - presumably from within the depths of the QML implementation. I don't know why this is happening - it smells like a Qt bug.
However giving the RoleGroupModel instance as the parent of each of the RoleModel instances seems to fix the problem.
Phil
More information about the PyQt
mailing list