Qt6: update the connect calls for QNetworkReply

Because of the old connect syntax used the incorrect signal names weren't
caught at compile time. To switch to the new syntax we had to make two
functions pure virtual in the WebServices class - let's hope I got that right.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-04-10 18:49:11 -10:00
parent e9b4d02d24
commit c41e2489a4
5 changed files with 34 additions and 4 deletions

View file

@ -37,10 +37,16 @@ QNetworkReply* CloudStorageAuthenticate::backend(const QString& email,const QStr
request->setRawHeader("User-Agent", userAgent.toUtf8());
request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
reply = manager()->post(*request, qPrintable(payload));
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(reply, &QNetworkReply::finished, this, &CloudStorageAuthenticate::uploadFinished);
connect(reply, &QNetworkReply::sslErrors, this, &CloudStorageAuthenticate::sslErrors);
connect(reply, &QNetworkReply::errorOccurred, this, &CloudStorageAuthenticate::uploadError);
#else
connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(uploadError(QNetworkReply::NetworkError)));
#endif
return reply;
}

View file

@ -255,13 +255,20 @@ void uploadDiveLogsDE::uploadDives(const QString &filename, const QString &useri
reply = manager()->post(request, multipart);
// connect signals from upload process
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(reply, &QNetworkReply::finished, this, &uploadDiveLogsDE::uploadFinishedSlot);
connect(reply, &QNetworkReply::errorOccurred, this, &uploadDiveLogsDE::uploadErrorSlot);
connect(reply, &QNetworkReply::uploadProgress, this, &uploadDiveLogsDE::updateProgressSlot);
connect(&timeout, &QTimer::timeout, this, &uploadDiveLogsDE::uploadTimeoutSlot);
#else
connect(reply, SIGNAL(finished()), this, SLOT(uploadFinishedSlot()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(uploadErrorSlot(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this,
SLOT(updateProgressSlot(qint64, qint64)));
connect(&timeout, SIGNAL(timeout()), this, SLOT(uploadTimeoutSlot()));
#endif
timeout.start(30000); // 30s
}

View file

@ -45,13 +45,19 @@ void uploadDiveShare::doUpload(bool selected, const QString &uid, bool noPublic)
reply = manager()->put(request, json_data);
// connect signals from upload process
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(reply, &QNetworkReply::finished, this, &uploadDiveShare::uploadFinishedSlot);
connect(reply, &QNetworkReply::errorOccurred, this, &uploadDiveShare::uploadErrorSlot);
connect(reply, &QNetworkReply::uploadProgress, this, &uploadDiveShare::updateProgressSlot);
connect(&timeout, &QTimer::timeout, this, &uploadDiveShare::uploadTimeoutSlot);
#else
connect(reply, SIGNAL(finished()), this, SLOT(uploadFinishedSlot()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(uploadErrorSlot(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this,
SLOT(updateProgressSlot(qint64, qint64)));
connect(&timeout, SIGNAL(timeout()), this, SLOT(uploadTimeoutSlot()));
#endif
timeout.start(30000); // 30s
}

View file

@ -107,12 +107,17 @@ void WebServices::updateProgress(qint64 current, qint64 total)
void WebServices::connectSignalsForDownload(QNetworkReply *reply)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(reply, &QNetworkReply::finished, this, &WebServices::downloadFinished);
connect(reply, &QNetworkReply::errorOccurred, this, &WebServices::downloadError);
connect(reply, &QNetworkReply::downloadProgress, this, &WebServices::updateProgress);
#else
connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this,
SLOT(updateProgress(qint64, qint64)));
#endif
timeout.start(30000); // 30s
}
@ -308,10 +313,14 @@ void DivelogsDeWebServices::startDownload()
body.addQueryItem("pass", ui.password->text().replace("+", "%2b"));
reply = manager()->post(request, body.query(QUrl::FullyEncoded).toLatin1());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(reply, &QNetworkReply::finished, this, &DivelogsDeWebServices::listDownloadFinished);
connect(reply, &QNetworkReply::errorOccurred, this, &DivelogsDeWebServices::downloadError);
#else
connect(reply, SIGNAL(finished()), this, SLOT(listDownloadFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(downloadError(QNetworkReply::NetworkError)));
#endif
timeout.start(30000); // 30s
}

View file

@ -26,6 +26,8 @@ slots:
virtual void startDownload() = 0;
virtual void startUpload() = 0;
virtual void buttonClicked(QAbstractButton *button) = 0;
virtual void downloadFinished() = 0;
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
void downloadTimedOut();
protected