Skip to content

Commit

Permalink
Move loading of QNetworkInformation to main()
Browse files Browse the repository at this point in the history
The `QNetworkInformation` will be used in multiple places. Do the
loading once before any uses.
  • Loading branch information
erikjv committed Jan 4, 2024
1 parent 772a93a commit 140276d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QCommandLineParser>
#include <QLibraryInfo>
#include <QMessageBox>
#include <QNetworkInformation>
#include <QProcess>
#include <QTimer>
#include <QTranslator>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 140276d

Please sign in to comment.