fixed crash when onError is not set

This commit is contained in:
fourtf 2018-05-14 15:12:09 +02:00
parent c42b6f5335
commit a0e33ef9e6

View file

@ -253,9 +253,9 @@ public:
data.onReplyCreated(reply); data.onReplyCreated(reply);
} }
QObject::connect(reply, &QNetworkReply::finished, worker, QObject::connect(reply, &QNetworkReply::finished, worker, [
[data = std::move(data), worker, reply, data = std::move(data), worker, reply, onFinished = std::move(onFinished)
onFinished = std::move(onFinished)]() mutable { ]() mutable {
if (data.caller == nullptr) { if (data.caller == nullptr) {
QByteArray bytes = reply->readAll(); QByteArray bytes = reply->readAll();
data.writeToCache(bytes); data.writeToCache(bytes);
@ -369,10 +369,14 @@ private:
worker->moveToThread(&NetworkManager::workerThread); worker->moveToThread(&NetworkManager::workerThread);
if (this->data.caller != nullptr) { if (this->data.caller != nullptr) {
QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller, QObject::connect(worker, &NetworkWorker::doneUrl,
[data = this->data](auto reply) mutable { this->data.caller, [data = this->data](auto reply) mutable {
auto &dat = data;
if (reply->error() != QNetworkReply::NetworkError::NoError) { if (reply->error() != QNetworkReply::NetworkError::NoError) {
if (data.onError) {
data.onError(reply->error()); data.onError(reply->error());
}
return; return;
} }