summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-12-09 17:42:06 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-12-09 17:42:06 +0200
commit04b62a46e9f28f0e3b4a4f2e3c3aa9c18445df2f (patch)
treea2577f727767def53e7cc7b62cff1ef6ff17531f
parente0acad42aa7dcee4fdea940d85c9bfeca20b0c4d (diff)
downloadsubsurface-04b62a46e9f28f0e3b4a4f2e3c3aa9c18445df2f.tar.gz
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 <neolit123@gmail.com>
-rw-r--r--qt-ui/subsurfacewebservices.cpp22
1 files changed, 15 insertions, 7 deletions
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 = &mp;
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, "<Login>");
@@ -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: