Modifying QStandardItemModel from non-UI QThread?

爱⌒轻易说出口 提交于 2019-12-22 11:46:10

问题


I have Qt4 app which binds QStandardItemModel to the QListView and have the model updated from background/non-UI thread.

Sometimes, when the QStandardItem's setText(..) method is called very repeatedly from the non-UI thread, the application will crash at a la dataChanged(..) handler. I can reproduce the issue by calling setText("xxxxx") repeatedly in a for loop. In my app, the data is read from network hence I update the model in separate, non-UI thread.

Is this a common pb? If I understand correctly, this is related to queued connection and QStandardItemModel is not thread safe? How to get around this issue?

Thanks!


回答1:


QStandardItemModel is part of the QtGui Library, iirc all classes in there are considered not threadsafe. You should be ok if you move the actual setting of the data into the GUI thread. You can do that pretty easily by using a queued signal from you network thread.



来源:https://stackoverflow.com/questions/4416706/modifying-qstandarditemmodel-from-non-ui-qthread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!