From 1a62ee2e57c1ab764ab49e71bb5fbe30c5d1feee Mon Sep 17 00:00:00 2001 From: Bruno Alexandre Rosa <1791393+brunoalr@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:29:02 -0300 Subject: [PATCH] fix: build on both qt < and >= 6.10.0 --- .github/workflows/desktop-build.yml | 6 +-- .../interface/widgets/server/games_model.cpp | 48 +++++++++++-------- .../interface/widgets/server/games_model.h | 2 + .../interface/widgets/tabs/tab_replays.cpp | 5 +- .../card/database/card_database_loader.cpp | 4 +- .../model/card_database_display_model.cpp | 7 +++ .../libcockatrice/utility/logger.cpp | 6 ++- servatrice/src/server_logger.cpp | 6 ++- 8 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 15410a384..215ddc227 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -278,7 +278,7 @@ jobs: continue-on-error: ${{matrix.allow-failure == 'yes'}} env: # Common parameters for all macOS builds - QT_VERSION: 6.6.* + QT_VERSION: 6.10.* QT_ARCH: clang_64 QT_MODULES: "qtimageformats qtmultimedia qtwebsockets" # Build-specific environment variables @@ -425,8 +425,8 @@ jobs: qt_arch: msvc2019_64 - target: 10 - qt_version: 6.6.* - qt_arch: msvc2019_64 + qt_version: 6.10.* + qt_arch: msvc2022_64 qt_modules: "qtimageformats qtmultimedia qtwebsockets" name: Windows ${{matrix.target}} diff --git a/cockatrice/src/interface/widgets/server/games_model.cpp b/cockatrice/src/interface/widgets/server/games_model.cpp index f05d47efe..5bf0a0b69 100644 --- a/cockatrice/src/interface/widgets/server/games_model.cpp +++ b/cockatrice/src/interface/widgets/server/games_model.cpp @@ -286,101 +286,111 @@ GamesProxyModel::GamesProxyModel(QObject *parent, const UserListProxy *_userList setDynamicSortFilter(true); } +void GamesProxyModel::applyFilterChange() +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) + beginFilterChange(); + endFilterChange(); +#else + invalidateFilter(); +#endif +} + void GamesProxyModel::setHideBuddiesOnlyGames(bool _showBuddiesOnlyGames) { hideBuddiesOnlyGames = _showBuddiesOnlyGames; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHideIgnoredUserGames(bool _hideIgnoredUserGames) { hideIgnoredUserGames = _hideIgnoredUserGames; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHideFullGames(bool _showFullGames) { hideFullGames = _showFullGames; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHideGamesThatStarted(bool _showGamesThatStarted) { hideGamesThatStarted = _showGamesThatStarted; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHidePasswordProtectedGames(bool _showPasswordProtectedGames) { hidePasswordProtectedGames = _showPasswordProtectedGames; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHideNotBuddyCreatedGames(bool value) { hideNotBuddyCreatedGames = value; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setHideOpenDecklistGames(bool _hideOpenDecklistGames) { hideOpenDecklistGames = _hideOpenDecklistGames; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setGameNameFilter(const QString &_gameNameFilter) { gameNameFilter = _gameNameFilter; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setCreatorNameFilter(const QString &_creatorNameFilter) { creatorNameFilter = _creatorNameFilter; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setGameTypeFilter(const QSet &_gameTypeFilter) { gameTypeFilter = _gameTypeFilter; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax) { maxPlayersFilterMin = _maxPlayersFilterMin; maxPlayersFilterMax = _maxPlayersFilterMax; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setMaxGameAge(const QTime &_maxGameAge) { maxGameAge = _maxGameAge; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setShowOnlyIfSpectatorsCanWatch(bool _showOnlyIfSpectatorsCanWatch) { showOnlyIfSpectatorsCanWatch = _showOnlyIfSpectatorsCanWatch; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setShowSpectatorPasswordProtected(bool _showSpectatorPasswordProtected) { showSpectatorPasswordProtected = _showSpectatorPasswordProtected; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setShowOnlyIfSpectatorsCanChat(bool _showOnlyIfSpectatorsCanChat) { showOnlyIfSpectatorsCanChat = _showOnlyIfSpectatorsCanChat; - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::setShowOnlyIfSpectatorsCanSeeHands(bool _showOnlyIfSpectatorsCanSeeHands) { showOnlyIfSpectatorsCanSeeHands = _showOnlyIfSpectatorsCanSeeHands; - invalidateFilter(); + applyFilterChange(); } int GamesProxyModel::getNumFilteredGames() const @@ -418,7 +428,7 @@ void GamesProxyModel::resetFilterParameters() showOnlyIfSpectatorsCanChat = false; showOnlyIfSpectatorsCanSeeHands = false; - invalidateFilter(); + applyFilterChange(); } bool GamesProxyModel::areFilterParametersSetToDefaults() const @@ -459,7 +469,7 @@ void GamesProxyModel::loadFilterParameters(const QMap &allGameType } } - invalidateFilter(); + applyFilterChange(); } void GamesProxyModel::saveFilterParameters(const QMap &allGameTypes) @@ -577,5 +587,5 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const void GamesProxyModel::refresh() { - invalidateFilter(); + applyFilterChange(); } diff --git a/cockatrice/src/interface/widgets/server/games_model.h b/cockatrice/src/interface/widgets/server/games_model.h index 1541b57bf..ae6855614 100644 --- a/cockatrice/src/interface/widgets/server/games_model.h +++ b/cockatrice/src/interface/widgets/server/games_model.h @@ -95,6 +95,8 @@ private: bool showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat, showOnlyIfSpectatorsCanSeeHands; + void applyFilterChange(); + public: explicit GamesProxyModel(QObject *parent = nullptr, const UserListProxy *_userListProxy = nullptr); diff --git a/cockatrice/src/interface/widgets/tabs/tab_replays.cpp b/cockatrice/src/interface/widgets/tabs/tab_replays.cpp index 836d900b6..f98cb8783 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_replays.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_replays.cpp @@ -440,7 +440,10 @@ void TabReplays::downloadFinished(const Response &r, const std::string &_data = resp.replay_data(); QFile f(filePath); - f.open(QIODevice::WriteOnly); + if (!f.open(QIODevice::WriteOnly)) { + qWarning() << "Failed to open file for writing:" << filePath; + return; + } f.write((const char *)_data.data(), _data.size()); f.close(); } diff --git a/libcockatrice_card/libcockatrice/card/database/card_database_loader.cpp b/libcockatrice_card/libcockatrice/card/database/card_database_loader.cpp index 0c9557418..07f8bf05a 100644 --- a/libcockatrice_card/libcockatrice/card/database/card_database_loader.cpp +++ b/libcockatrice_card/libcockatrice/card/database/card_database_loader.cpp @@ -36,8 +36,8 @@ CardDatabaseLoader::~CardDatabaseLoader() LoadStatus CardDatabaseLoader::loadFromFile(const QString &fileName) { QFile file(fileName); - file.open(QIODevice::ReadOnly); - if (!file.isOpen()) { + const auto isOpen = file.open(QIODevice::ReadOnly); + if (!isOpen) { return FileError; } diff --git a/libcockatrice_card/libcockatrice/card/database/model/card_database_display_model.cpp b/libcockatrice_card/libcockatrice/card/database/model/card_database_display_model.cpp index fc1b20cf6..ba2d4924f 100644 --- a/libcockatrice_card/libcockatrice/card/database/model/card_database_display_model.cpp +++ b/libcockatrice_card/libcockatrice/card/database/model/card_database_display_model.cpp @@ -188,9 +188,16 @@ void CardDatabaseDisplayModel::clearFilterAll() cardText.clear(); cardTypes.clear(); cardColors.clear(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) + beginFilterChange(); +#endif if (filterTree != nullptr) filterTree->clear(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) + endFilterChange(); +#else invalidateFilter(); +#endif } void CardDatabaseDisplayModel::setFilterTree(FilterTree *_filterTree) diff --git a/libcockatrice_utility/libcockatrice/utility/logger.cpp b/libcockatrice_utility/libcockatrice/utility/logger.cpp index 0184146ae..c54cc1a20 100644 --- a/libcockatrice_utility/libcockatrice/utility/logger.cpp +++ b/libcockatrice_utility/libcockatrice/utility/logger.cpp @@ -51,7 +51,11 @@ void Logger::openLogfileSession() } fileHandle.setFileName(LOGGER_FILENAME); - fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); + const auto result = fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); + if (!result) { + std::cerr << "Error: Failed to open log file: " << fileHandle.errorString().toStdString() << std::endl; + return; + } fileStream.setDevice(&fileHandle); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) fileStream << "Log session started at " << QDateTime::currentDateTime().toString() << Qt::endl; diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 9e40ac7b4..3fabf6fce 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -120,7 +120,11 @@ void ServerLogger::rotateLogs() flushBuffer(); logFile->close(); - logFile->open(QIODevice::Append); + const auto result = logFile->open(QIODevice::Append); + if (!result) { + std::cerr << "ERROR: can't open() logfile." << std::endl; + return; + } } QFile *ServerLogger::logFile;