From 5c5dcd555bd359765423e44e3759db5a3e437815 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Thu, 28 Aug 2025 14:46:56 +0200 Subject: [PATCH] Fix compilation warnings about QFile::open --- autotests/testutils.h | 5 +++-- autotests/timelinemessagemodeltest.cpp | 2 +- memorytests/memtesttimelinemodel.h | 6 +++++- src/libneochat/neochatconnection.cpp | 6 +++++- src/libneochat/neochatroom.cpp | 5 ++++- src/messagecontent/models/messagecontentmodel.h | 6 +++++- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/autotests/testutils.h b/autotests/testutils.h index ccfa66100..8fb510913 100644 --- a/autotests/testutils.h +++ b/autotests/testutils.h @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2023 James Graham // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +#include #include #include @@ -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 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(testSyncJson); } diff --git a/autotests/timelinemessagemodeltest.cpp b/autotests/timelinemessagemodeltest.cpp index 41358fdfd..80e1db4fb 100644 --- a/autotests/timelinemessagemodeltest.cpp +++ b/autotests/timelinemessagemodeltest.cpp @@ -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(); diff --git a/memorytests/memtesttimelinemodel.h b/memorytests/memtesttimelinemodel.h index f9a7aaaa4..ece6d89db 100644 --- a/memorytests/memtesttimelinemodel.h +++ b/memorytests/memtesttimelinemodel.h @@ -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); diff --git a/src/libneochat/neochatconnection.cpp b/src/libneochat/neochatconnection.cpp index 0db72a33f..a2bc2d732 100644 --- a/src/libneochat/neochatconnection.cpp +++ b/src/libneochat/neochatconnection.cpp @@ -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; diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index 177b6abd4..18a250884 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -261,7 +261,10 @@ QCoro::Task 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())) diff --git a/src/messagecontent/models/messagecontentmodel.h b/src/messagecontent/models/messagecontentmodel.h index 8e44756de..7a446ea6b 100644 --- a/src/messagecontent/models/messagecontentmodel.h +++ b/src/messagecontent/models/messagecontentmodel.h @@ -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();