What is the correct way to “stop / shutdown” a QNetworkAccessManager?

独自空忆成欢 提交于 2019-12-11 14:15:10

问题


I have a QNetworkAccessManager . Let's assume I have a pending request:

QNetworkRequest request(url);
this->m_networkManager->get(request)

Can I shutdown the QNetworkAccessManager at any time? I am asking because I see a write access violation when I destruct my object m_networkManager during a pending get request.

Or how can I safely destroy the manager, there seems to be no stop or shutdown functionality.


回答1:


The root cause is that our QNetworkAccessManager is used in a threaded worker (1). So obviously when the QNetworkAccessManager is deleted, and in this step (and only then) cleans up pending QNetworkReply objects, the problem arises.

Analysis: With no pending replies, or when used in the main thread, there is no issue in the same scenario. The issue can be avoided if the QNetworkAccessManager is deleted just before it is moved back to the main thread. Conclusion (or speculation): The issue occurs when the QNetworkAccessManager tries to delete a QNetworkReply created in a different thread.

(1) It is understood that requests are performed asynchronously - we have good design reasons for the threaded worker.



来源:https://stackoverflow.com/questions/33906235/what-is-the-correct-way-to-stop-shutdown-a-qnetworkaccessmanager

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