From 04b62a46e9f28f0e3b4a4f2e3c3aa9c18445df2f Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 9 Dec 2013 17:42:06 +0200 Subject: Divelogs.de: attempt to impletent 'Cancel' properly The correct way to stop the upload/download is to use reply->abort(). If the dialog closes, post exec() we check if the reply 'isOpen' and abort and delete it. Without this modification the program seems to crash as the connection is still in action and it attempts to read an already deleted file. Signed-off-by: Lubomir I. Ivanov --- qt-ui/subsurfacewebservices.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'qt-ui/subsurfacewebservices.cpp') diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 13a5a8a87..a336a4864 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -327,9 +327,11 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) } break; case QDialogButtonBox::RejectRole: - // we may want to clean up after ourselves - // reply->deleteLater(); - reply = NULL; + if (reply != NULL && reply->isOpen()) { + reply->abort(); + delete reply; + reply = NULL; + } resetState(); break; case QDialogButtonBox::HelpRole: @@ -569,10 +571,15 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) multipart = ∓ hideDownload(); + resetState(); exec(); - multipart = NULL; - delete reply; // we need to ensure it has stopped using our QHttpMultiPart + multipart = NULL; + if (reply != NULL && reply->isOpen()) { + reply->abort(); + delete reply; + reply = NULL; + } } DivelogsDeWebServices::DivelogsDeWebServices(QWidget* parent, Qt::WindowFlags f): WebServices(parent, f) @@ -755,6 +762,8 @@ void DivelogsDeWebServices::uploadFinished() // check what the server sent us: it might contain // an error condition, such as a failed login QByteArray xmlData = reply->readAll(); + reply->deleteLater(); + reply = NULL; char *resp = xmlData.data(); if (resp) { char *parsed = strstr(resp, ""); @@ -782,7 +791,7 @@ void DivelogsDeWebServices::setStatusText(int status) void DivelogsDeWebServices::downloadError(QNetworkReply::NetworkError) { resetState(); - ui.status->setText(tr("Download error: %1").arg(reply->errorString())); + ui.status->setText(tr("Error: %1").arg(reply->errorString())); reply->deleteLater(); reply = NULL; } @@ -820,7 +829,6 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) case QDialogButtonBox::RejectRole: // these two seem to be causing a crash: // reply->deleteLater(); - // reply = NULL; resetState(); break; case QDialogButtonBox::HelpRole: -- cgit v1.2.3-70-g09d2