Fix compilation warnings about QFile::open

This commit is contained in:
Tobias Fella
2025-08-28 14:46:56 +02:00
parent 8098fce461
commit 5c5dcd555b
6 changed files with 23 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include <QTest>
#include <Quotient/events/event.h>
#include <Quotient/syncdata.h>
@@ -32,7 +33,7 @@ public:
if (!syncFileName.isEmpty()) {
QFile testSyncFile;
testSyncFile.setFileName(QStringLiteral(DATA_DIR) + u'/' + syncFileName);
testSyncFile.open(QIODevice::ReadOnly);
Q_UNUSED(testSyncFile.open(QIODevice::ReadOnly));
const auto testSyncJson = QJsonDocument::fromJson(testSyncFile.readAll());
Quotient::SyncRoomData roomData(id(), Quotient::JoinState::Join, testSyncJson.object());
update(std::move(roomData));
@@ -46,7 +47,7 @@ inline Quotient::event_ptr_tt<EventT> loadEventFromFile(const QString &eventFile
if (!eventFileName.isEmpty()) {
QFile testEventFile;
testEventFile.setFileName(QStringLiteral(DATA_DIR) + u'/' + eventFileName);
testEventFile.open(QIODevice::ReadOnly);
Q_UNUSED(testEventFile.open(QIODevice::ReadOnly));
auto testSyncJson = QJsonDocument::fromJson(testEventFile.readAll()).object();
return Quotient::loadEvent<EventT>(testSyncJson);
}

View File

@@ -161,7 +161,7 @@ void TimelineMessageModelTest::pendingEvent()
// different every time.
QFile testSyncFile;
testSyncFile.setFileName(QStringLiteral(DATA_DIR) + u'/' + u"test-pending-sync.json"_s);
testSyncFile.open(QIODevice::ReadOnly);
QVERIFY(testSyncFile.open(QIODevice::ReadOnly));
auto testSyncJson = QJsonDocument::fromJson(testSyncFile.readAll());
auto root = testSyncJson.object();
auto timeline = root["timeline"_L1].toObject();

View File

@@ -37,7 +37,11 @@ public:
if (!syncFileName.isEmpty()) {
QFile testSyncFile;
testSyncFile.setFileName(QStringLiteral(DATA_DIR) + u'/' + syncFileName);
testSyncFile.open(QIODevice::ReadOnly);
auto ok = testSyncFile.open(QIODevice::ReadOnly);
if (!ok) {
qWarning() << "Failed to open" << testSyncFile.fileName() << testSyncFile.errorString();
}
auto testSyncJson = QJsonDocument::fromJson(testSyncFile.readAll()).object();
auto timelineJson = testSyncJson["timeline"_L1].toObject();
timelineJson["events"_L1] = multiplyEvents(timelineJson["events"_L1].toArray(), 100);

View File

@@ -533,7 +533,11 @@ KeyImport::Error NeoChatConnection::exportMegolmSessions(const QString &passphra
}
QUrl url(path);
QFile file(url.toLocalFile());
file.open(QFile::WriteOnly);
auto ok = file.open(QFile::WriteOnly);
if (!ok) {
qWarning() << "Failed to open" << file.fileName() << file.errorString();
return KeyImport::OtherError;
}
file.write(result.value());
file.close();
return KeyImport::Success;

View File

@@ -261,7 +261,10 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body, std::optiona
QTemporaryFile file;
file.setFileTemplate(QStringLiteral("XXXXXX.jpg"));
file.open();
auto ok = file.open();
if (!ok) {
qWarning() << "Failed to open" << file.fileName() << file.errorString();
}
const auto thumbnailImage = sink.videoFrame().toImage();
Q_UNUSED(thumbnailImage.save(file.fileName()))

View File

@@ -189,7 +189,11 @@ private:
}
QFile file(fileTransferInfo.localPath.path());
file.open(QIODevice::ReadOnly);
auto ok = file.open(QIODevice::ReadOnly);
if (!ok) {
qWarning() << "Failed to open" << fileTransferInfo.localPath.path() << file.errorString();
}
beginInsertRows({}, std::distance(m_components.begin(), it) + 1, std::distance(m_components.begin(), it) + 1);
it = m_components.insert(it + 1, MessageComponent{MessageComponentType::Code, QString::fromStdString(file.readAll().toStdString()), {{u"class"_s, definitionForFile.name()}}});
endInsertRows();