From 38a3bf2ef81077488fac84460d58aa9e70053ee8 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 5 Oct 2025 15:18:54 +0200 Subject: [PATCH] fix: warnings when compiling with Qt 6.10 (#6422) --- CHANGELOG.md | 1 + CMakeLists.txt | 4 ++++ mocks/include/mocks/EmptyApplication.hpp | 10 ++++++---- src/RunGui.cpp | 2 +- src/common/Credentials.cpp | 11 +++++++++-- src/common/LinkParser.cpp | 8 +++++++- src/common/Modes.cpp | 5 ++++- src/common/WindowDescriptors.cpp | 5 ++++- src/controllers/plugins/PluginController.cpp | 7 ++++++- src/providers/emoji/Emojis.cpp | 7 ++++++- src/singletons/ImageUploader.cpp | 7 ++++++- src/singletons/Updates.cpp | 12 ++++++++++-- src/singletons/helper/LoggingChannel.cpp | 15 +++++++++++++-- src/widgets/dialogs/SettingsDialog.cpp | 7 ++++++- src/widgets/settingspages/AboutPage.cpp | 13 +++++++++++-- src/widgets/settingspages/CommandPage.cpp | 11 +++++++++-- tests/src/Plugins.cpp | 4 ++-- 17 files changed, 105 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69a4b9fe..17212abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Dev: Correct handling of eventsubs without any account. (#6503) - Dev: Removed dependency to Qt5 Compatibility module by updating libcommuni. (#6500) - Dev: Merged emote element flags from different providers into two. (#6511) +- Dev: Fixed warnings on Qt 6.10. (#6422) - Dev: Removed unused method in `Emojis`. (#6517) - Dev: Refactored `Emotes` into `EmoteController`. (#6516) - Dev: Added Qt keyword and warning flags project wide. (#6520) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15a3aa8f..5cb3ad58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,10 @@ find_package(Qt${MAJOR_QT_VERSION} REQUIRED Svg Concurrent ) +if(CHATTERINO_ALLOW_PRIVATE_QT_API) + # Only exists since 6.10 and prints a warning regarding private headers + find_package(Qt${MAJOR_QT_VERSION} COMPONENTS GuiPrivate) +endif() message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}") diff --git a/mocks/include/mocks/EmptyApplication.hpp b/mocks/include/mocks/EmptyApplication.hpp index 1e6ade4f..0f09cf2a 100644 --- a/mocks/include/mocks/EmptyApplication.hpp +++ b/mocks/include/mocks/EmptyApplication.hpp @@ -17,10 +17,12 @@ public: explicit EmptyApplication(const QString &settingsData) { QFile settingsFile(this->settingsDir.filePath("settings.json")); - settingsFile.open(QIODevice::WriteOnly | QIODevice::Text); - settingsFile.write(settingsData.toUtf8()); - settingsFile.flush(); - settingsFile.close(); + if (settingsFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + settingsFile.write(settingsData.toUtf8()); + settingsFile.flush(); + settingsFile.close(); + } } ~EmptyApplication() override = default; diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 77b56a1d..fcc501d9 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -114,7 +114,7 @@ void createRunningFile(const QString &path) { QFile runningFile(path); - runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + std::ignore = runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate); runningFile.flush(); runningFile.close(); } diff --git a/src/common/Credentials.cpp b/src/common/Credentials.cpp index 7e5e5655..306bb8f7 100644 --- a/src/common/Credentials.cpp +++ b/src/common/Credentials.cpp @@ -65,14 +65,21 @@ QString insecurePath() QJsonDocument loadInsecure() { QFile file(insecurePath()); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODevice::ReadOnly)) + { + return {}; + } + return QJsonDocument::fromJson(file.readAll()); } void storeInsecure(const QJsonDocument &doc) { QSaveFile file(insecurePath()); - file.open(QIODevice::WriteOnly); + if (!file.open(QIODevice::WriteOnly)) + { + return; + } file.write(doc.toJson()); file.commit(); } diff --git a/src/common/LinkParser.cpp b/src/common/LinkParser.cpp index 64262d3a..6e88fd17 100644 --- a/src/common/LinkParser.cpp +++ b/src/common/LinkParser.cpp @@ -1,6 +1,7 @@ #define QT_NO_CAST_FROM_ASCII // avoids unexpected implicit casts #include "common/LinkParser.hpp" +#include "common/QLogging.hpp" #include "util/QCompareTransparent.hpp" #include @@ -20,7 +21,12 @@ TldSet &tlds() { static TldSet tlds = [] { QFile file(QStringLiteral(":/tlds.txt")); - file.open(QFile::ReadOnly); + bool ok = file.open(QFile::ReadOnly); + if (!ok) + { + assert(false && "Resources not available"); + qCWarning(chatterinoApp) << "Resources not available"; + } QTextStream stream(&file); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) diff --git a/src/common/Modes.cpp b/src/common/Modes.cpp index a445a77c..66d4d060 100644 --- a/src/common/Modes.cpp +++ b/src/common/Modes.cpp @@ -9,7 +9,10 @@ namespace chatterino { Modes::Modes() { QFile file(combinePath(QCoreApplication::applicationDirPath(), "modes")); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODevice::ReadOnly)) + { + return; + } while (!file.atEnd()) { diff --git a/src/common/WindowDescriptors.cpp b/src/common/WindowDescriptors.cpp index 9d2e43d5..ed08f0cd 100644 --- a/src/common/WindowDescriptors.cpp +++ b/src/common/WindowDescriptors.cpp @@ -14,7 +14,10 @@ namespace { QJsonArray loadWindowArray(const QString &settingsPath) { QFile file(settingsPath); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODevice::ReadOnly)) + { + return {}; + } QByteArray data = file.readAll(); QJsonDocument document = QJsonDocument::fromJson(data); QJsonArray windows_arr = document.object().value("windows").toArray(); diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 6c315daf..db52eb78 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -92,7 +92,12 @@ bool PluginController::tryLoadFromDir(const QDir &pluginDir) return false; } QFile infoFile(infojson.absoluteFilePath()); - infoFile.open(QIODevice::ReadOnly); + if (!infoFile.open(QIODevice::ReadOnly)) + { + qCWarning(chatterinoLua) + << "Could not open info.json" << infoFile.errorString(); + return false; + } auto everything = infoFile.readAll(); auto doc = QJsonDocument::fromJson(everything); if (!doc.isObject()) diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index b132b3f2..358c40d1 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -172,7 +172,12 @@ void Emojis::loadEmojis() { // Current version: https://github.com/iamcal/emoji-data/blob/v15.1.1/emoji.json (Emoji version 15.1 (2023)) QFile file(":/emoji.json"); - file.open(QFile::ReadOnly); + if (!file.open(QFile::ReadOnly)) + { + assert(false && "Resources not available"); + qCWarning(chatterinoEmoji) << "Resources not available"; + return; + } QTextStream s1(&file); QString data = s1.readAll(); rapidjson::Document root; diff --git a/src/singletons/ImageUploader.cpp b/src/singletons/ImageUploader.cpp index dcc21408..ede33c26 100644 --- a/src/singletons/ImageUploader.cpp +++ b/src/singletons/ImageUploader.cpp @@ -140,7 +140,12 @@ void ImageUploader::logToFile(const QString &originalFilePath, // local path to an image (can be empty) // timestamp QSaveFile logSaveFile(logFileName); - logSaveFile.open(QIODevice::WriteOnly | QIODevice::Text); + if (!logSaveFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + qCDebug(chatterinoImageuploader) + << "Failed to open log file" << logSaveFile.errorString(); + return; + } QJsonArray entries = QJsonDocument::fromJson(logs).array(); entries.push_back(newLogEntry); logSaveFile.write(QJsonDocument(entries).toJson()); diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 6141a2f7..b2e4429b 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -178,7 +178,13 @@ void Updates::installUpdates() combinePath(this->paths.miscDirectory, "update.zip"); QFile file(filename); - file.open(QIODevice::Truncate | QIODevice::WriteOnly); + if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) + { + qCWarning(chatterinoUpdate) + << "Failed to save update.zip" << file.errorString(); + this->setStatus_(WriteFileFailed); + return; + } if (file.write(object) == -1) { @@ -238,7 +244,9 @@ void Updates::installUpdates() combinePath(this->paths.miscDirectory, "Update.exe"); QFile file(filePath); - file.open(QIODevice::Truncate | QIODevice::WriteOnly); + // write() will fail if we couldn't open + std::ignore = + file.open(QIODevice::Truncate | QIODevice::WriteOnly); if (file.write(object) == -1) { diff --git a/src/singletons/helper/LoggingChannel.cpp b/src/singletons/helper/LoggingChannel.cpp index 58ecf686..d2e26b83 100644 --- a/src/singletons/helper/LoggingChannel.cpp +++ b/src/singletons/helper/LoggingChannel.cpp @@ -128,7 +128,12 @@ void LoggingChannel::openLogFile() qCDebug(chatterinoHelper) << "Logging to" << fileName; this->fileHandle.setFileName(fileName); - this->fileHandle.open(QIODevice::Append); + if (!this->fileHandle.open(QIODevice::Append)) + { + qCDebug(chatterinoHelper) + << "Failed to open file" << this->fileHandle.errorString(); + return; + } appendLine(this->fileHandle, generateOpeningString(now)); } @@ -159,7 +164,13 @@ void LoggingChannel::openStreamLogFile(const QString &streamID) qCDebug(chatterinoHelper) << "Logging stream to" << fileName; this->currentStreamFileHandle.setFileName(fileName); - this->currentStreamFileHandle.open(QIODevice::Append); + if (!this->currentStreamFileHandle.open(QIODevice::Append)) + { + qCDebug(chatterinoHelper) + << "Failed to open file" + << this->currentStreamFileHandle.errorString(); + return; + } appendLine(this->currentStreamFileHandle, generateOpeningString(now)); } diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index b0a0bbf6..0958053b 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -2,6 +2,7 @@ #include "Application.hpp" #include "common/Args.hpp" +#include "common/QLogging.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/hotkeys/HotkeyController.hpp" #include "singletons/Settings.hpp" @@ -47,7 +48,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) this->resize(915, 600); this->themeChangedEvent(); QFile styleFile(":/qss/settings.qss"); - styleFile.open(QFile::ReadOnly); + if (!styleFile.open(QFile::ReadOnly)) + { + assert(false && "Resources not loaded"); + qCWarning(chatterinoWidget) << "Resources not loaded"; + } QString stylesheet = QString::fromUtf8(styleFile.readAll()); this->setStyleSheet(stylesheet); diff --git a/src/widgets/settingspages/AboutPage.cpp b/src/widgets/settingspages/AboutPage.cpp index bc2a6b1a..4e2406bd 100644 --- a/src/widgets/settingspages/AboutPage.cpp +++ b/src/widgets/settingspages/AboutPage.cpp @@ -158,7 +158,11 @@ AboutPage::AboutPage() auto l = contributors.emplace(); QFile contributorsFile(":/contributors.txt"); - contributorsFile.open(QFile::ReadOnly); + if (!contributorsFile.open(QFile::ReadOnly)) + { + assert(false && "Resources not loaded"); + qCWarning(chatterinoWidget) << "Resources not loaded"; + } QTextStream stream(&contributorsFile); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -265,7 +269,12 @@ void AboutPage::addLicense(QFormLayout *form, const QString &name, auto *edit = new QTextEdit; QFile file(licenseLink); - file.open(QIODevice::ReadOnly); + if (!file.open(QIODevice::ReadOnly)) + { + assert(false && "License not found"); + qCWarning(chatterinoWidget) + << "License not found" << licenseLink; + } edit->setText(file.readAll()); edit->setReadOnly(true); diff --git a/src/widgets/settingspages/CommandPage.cpp b/src/widgets/settingspages/CommandPage.cpp index efff8029..ea5847b3 100644 --- a/src/widgets/settingspages/CommandPage.cpp +++ b/src/widgets/settingspages/CommandPage.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -105,9 +106,15 @@ CommandPage::CommandPage() auto *button = new QPushButton("Import commands from Chatterino 1"); this->view->addCustomButton(button); - QObject::connect(button, &QPushButton::clicked, this, [] { + QObject::connect(button, &QPushButton::clicked, this, [this] { QFile c1settings(c1settingsPath()); - c1settings.open(QIODevice::ReadOnly); + if (!c1settings.open(QIODevice::ReadOnly)) + { + QMessageBox::warning( + this, "Chatterino 1 Importer", + "Failed to read settings: " + c1settings.errorString()); + return; + } for (const auto &line : QString(c1settings.readAll()) .split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts)) diff --git a/tests/src/Plugins.cpp b/tests/src/Plugins.cpp index 5f8eb7eb..0eae2d6d 100644 --- a/tests/src/Plugins.cpp +++ b/tests/src/Plugins.cpp @@ -479,7 +479,7 @@ TEST_F(PluginTest, ioNoPerms) configure(); auto file = rawpl->dataDirectory().filePath("testfile"); QFile f(file); - f.open(QFile::WriteOnly); + EXPECT_TRUE(f.open(QFile::WriteOnly)); f.write(TEST_FILE_DATA); f.close(); @@ -531,7 +531,7 @@ TEST_F(PluginTest, requireNoData) auto file = rawpl->dataDirectory().filePath("thisiscode.lua"); QFile f(file); - f.open(QFile::WriteOnly); + EXPECT_TRUE(f.open(QFile::WriteOnly)); f.write(R"lua(print("Data was executed"))lua"); f.close();