PDA

View Full Version : Problem with QNetworkReply::abort()



themagician
4th June 2015, 15:48
I have this class called HttpDownload Header (https://github.com/labyrinthofdreams/screenpicker/blob/dev/httpdownload.hpp) / Source (https://github.com/labyrinthofdreams/screenpicker/blob/dev/httpdownload.cpp). It's basically a simple wrapper for QNetworkReply. The objects are created here (https://github.com/labyrinthofdreams/screenpicker/blob/dev/mainwindow.cpp#L1555) when the user wants to open a new network link via the OpenDialog. That HttpDownload is then started here (https://github.com/labyrinthofdreams/screenpicker/blob/dev/downloadsdialog.cpp#L39) by calling its start method and added to a model that outputs to a QListView using a custom delegate. The QListView displays a progress bar for each HttpDownload which reports its progress via the model. It works. But if I then add another context menu here (https://github.com/labyrinthofdreams/screenpicker/blob/dev/downloadsdialog.cpp#L71) that lets you stop HttpDownload by calling a new method download->abort() whose implementation goes like this:


void HttpDownload::abort()
{
if(reply->isFinished()) {
return;
}

reply->abort();

emit updated();
}

Well that works too, however, after I've aborted one HttpDownload, all subsequent HttpDownloads won't start downloading. At all. They do nothing. So when I call the start (https://github.com/labyrinthofdreams/screenpicker/blob/dev/httpdownload.cpp#L45) method here (https://github.com/labyrinthofdreams/screenpicker/blob/dev/downloadsdialog.cpp#L41), it won't start downloading. Any ideas? I've tried replacing reply->abort() with reply->close() but it does the same thing. Thanks.

themagician
5th June 2015, 21:27
The problem seems to have fixed itself.Here's (https://github.com/labyrinthofdreams/screenpicker/commit/d48477cfdc995aa0c98310b0e33755527d2c3193) the code for the abort feature. It's exactly the same as before so I've no idea why it wasn't working earlier. I just took it from git stash today and tried again and it worked.

(I didn't see an edit button so I made a new post).