From 140276db5d1b790effca7c9e7673b098687f9f7e Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 20 Oct 2023 15:00:19 +0200 Subject: [PATCH] Move loading of `QNetworkInformation` to `main()` The `QNetworkInformation` will be used in multiple places. Do the loading once before any uses. --- src/gui/accountstate.cpp | 6 ++---- src/gui/main.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index a4477e716f4..598cc895e95 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -115,8 +115,8 @@ AccountState::AccountState(AccountPtr account) Qt::QueuedConnection); #if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) - if (QNetworkInformation::loadDefaultBackend()) { - connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, [this](QNetworkInformation::Reachability reachability) { + if (QNetworkInformation *qNetInfo = QNetworkInformation::instance()) { + connect(qNetInfo, &QNetworkInformation::reachabilityChanged, this, [this](QNetworkInformation::Reachability reachability) { switch (reachability) { case QNetworkInformation::Reachability::Online: [[fallthrough]]; @@ -136,8 +136,6 @@ AccountState::AccountState(AccountPtr account) break; } }); - } else { - qCWarning(lcAccountState) << "Failed to load QNetworkInformation"; } #endif // as a fallback and to recover after server issues we also poll diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 19f36c1f3ae..83d16529711 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -448,6 +449,14 @@ int main(int argc, char **argv) return -1; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if (!QNetworkInformation::loadDefaultBackend()) { + qCWarning(lcMain) << "Failed to load QNetworkInformation"; + } +#else + qCWarning(lcMain) << "QNetworkInformation is not available"; +#endif + setupLogging(options); platform->setApplication(&app);