From 3721084d21bb486046ced1e88116aeca3fafe1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 15 Nov 2019 23:41:30 +0100 Subject: [PATCH] Made the code compile on QT5 < 5.9 + propper error handling --- src/data/gpiparser.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/data/gpiparser.cpp b/src/data/gpiparser.cpp index cd529a07..6939e0be 100644 --- a/src/data/gpiparser.cpp +++ b/src/data/gpiparser.cpp @@ -402,18 +402,20 @@ static quint32 readImageInfo(QDataStream &stream, Waypoint &waypoint, ba.resize(size); stream.readRawData(ba.data(), ba.size()); - QBuffer buf(&ba); - QImageReader ir(&buf); + if (tempDir().isValid()) { + QBuffer buf(&ba); + QImageReader ir(&buf); - QByteArray id(fileName.toUtf8() + QByteArray::number(imgId++)); - QFile imgFile(tempDir().filePath(QString("%0.%1").arg( - QCryptographicHash::hash(id, QCryptographicHash::Sha1).toHex(), - QString(ir.format())))); - imgFile.open(QIODevice::WriteOnly); - imgFile.write(ba); - imgFile.close(); + QByteArray id(fileName.toUtf8() + QByteArray::number(imgId++)); + QFile imgFile(tempDir().path() + "/" + QString("%0.%1").arg( + QCryptographicHash::hash(id, QCryptographicHash::Sha1).toHex(), + QString(ir.format()))); + imgFile.open(QIODevice::WriteOnly); + imgFile.write(ba); + imgFile.close(); - waypoint.addImage(ImageInfo(imgFile.fileName(), ir.size())); + waypoint.addImage(ImageInfo(imgFile.fileName(), ir.size())); + } if (size + 5 != rh.size) stream.setStatus(QDataStream::ReadCorruptData);