Add some error checks to Image::loadImage

Add default value to loadedPixmap
This commit is contained in:
Rasmus Karlsson
2018-04-16 23:48:30 +02:00
parent ea691635a1
commit 5f142e8d52
3 changed files with 45 additions and 10 deletions
+20 -4
View File
@@ -135,9 +135,15 @@ public:
// qDebug() << "Loaded cached resource" << this->data.request.url();
onFinished(bytes);
bool success = onFinished(bytes);
cachedFile.close();
if (!success) {
// The images were not successfully loaded from the file
// XXX: Invalidate the cache file so we don't attempt to load it again next
// time
}
}
}
}
@@ -160,7 +166,9 @@ public:
return;
}
QByteArray bytes = reply->readAll();
QByteArray readBytes = reply->readAll();
QByteArray bytes;
bytes.setRawData(readBytes.data(), readBytes.size());
data.writeToCache(bytes);
onFinished(bytes);
@@ -212,18 +220,26 @@ public:
template <typename FinishedCallback>
void getJSON(FinishedCallback onFinished)
{
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) {
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool {
auto object = parseJSONFromData(bytes);
onFinished(object);
// XXX: Maybe return onFinished? For now I don't want to force onFinished to have a
// return value
return true;
});
}
template <typename FinishedCallback>
void getJSON2(FinishedCallback onFinished)
{
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) {
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool {
auto object = parseJSONFromData2(bytes);
onFinished(object);
// XXX: Maybe return onFinished? For now I don't want to force onFinished to have a
// return value
return true;
});
}
};