How to properly stop QNetworkRequest ?
Hi, I've got a problem with my HttpClient, when I'm trying to stop/cancel request my application crashes... How can I cancel it properly ?
After when I'm trying to stop by this function:
Code:
void HttpClient::stop(){
if(m_reply) {
m_reply->abort();
}
}
it crashes on: loop.exec();
in function 'wait for finish'...
Code:
void HttpClient::waitForFinish(QNetworkReply *reply)
{
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
}
Code:
{
if(url.isEmpty()){
Logger::getInstance()->Error(trUtf8("HttpClient: GET Response <Url is empty!>"));
}
m_reply = m_manager->get(*this->generateRequest(url, false));
waitForFinish(m_reply);
if(!m_reply){
return "";
}
... code
This problem occurs sometimes, not always. I think that if, in another thread still performs and here is aborted it causes this crash...
Any idea ?
Thanks for any help ;)
Re: How to properly stop QNetworkRequest ?
Since you are using a nested event loop, have you checked if you enter the get() method maybe more than once?
Also the * at this->generateRequest looks peculiar, almost like if the return value of generateRequest is QUrl* and not QUrl.
Cheers,
_
Re: How to properly stop QNetworkRequest ?
You mentioned threads. Are HttpClient::stop() and HttpClient::get() executed by distinct threads? That would be a problem.