Skip to content

Commit 590fe5c

Browse files
erikjvTheOneRing
authored andcommitted
Always log the available QetworkInformation backends
This will also log the available backends when a warning occurs that no backend got loaded.
1 parent b8a857f commit 590fe5c

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/gui/application.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ Application::Application(Platform *platform, const QString &displayLanguage, boo
122122
// Cleanup at Quit.
123123
connect(qApp, &QCoreApplication::aboutToQuit, this, &Application::slotCleanup);
124124
qApp->installEventFilter(this);
125-
126-
#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
127-
if (!QNetworkInformation::loadDefaultBackend()) {
128-
qCWarning(lcApplication) << "Failed to load QNetworkInformation";
129-
} else {
130-
connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this,
131-
[this](QNetworkInformation::Reachability reachability) { qCInfo(lcApplication) << "Connection Status changed to:" << reachability; });
132-
}
133-
#endif
134125
}
135126

136127
Application::~Application()

src/gui/main.cpp

+27-12
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ void setupLogging(const CommandLineOptions &options)
249249
qCInfo(lcMain) << "Arguments:" << qApp->arguments();
250250
}
251251

252+
void loadQNetworkInformationBackend()
253+
{
254+
#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
255+
if (!QNetworkInformation::loadDefaultBackend()) {
256+
qCWarning(lcMain) << "Failed to load default backend of QNetworkInformation.";
257+
if (!QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Metered)) {
258+
qCWarning(lcMain) << "Failed to load backend of QNetworkInformation by metered feature.";
259+
if (!QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
260+
qCWarning(lcMain) << "Failed to load backend of QNetworkInformation by reachability feature.";
261+
qCWarning(lcMain) << "Available backends:" << QNetworkInformation::availableBackends().join(QStringLiteral(", "));
262+
return;
263+
}
264+
}
265+
}
266+
qCDebug(lcMain) << "Loaded network information backend:" << QNetworkInformation::instance()->backendName();
267+
qCDebug(lcMain) << "Supported features:" << QNetworkInformation::instance()->supportedFeatures();
268+
qCDebug(lcMain) << "Available backends:" << QNetworkInformation::availableBackends().join(QStringLiteral(", "));
269+
if (auto qni = QNetworkInformation::instance()) {
270+
QObject::connect(qni, &QNetworkInformation::reachabilityChanged,
271+
[](QNetworkInformation::Reachability reachability) { qCInfo(lcApplication) << "Connection Status changed to:" << reachability; });
272+
}
273+
#else
274+
qCWarning(lcMain) << "QNetworkInformation is not available on this platform";
275+
#endif
276+
}
277+
252278
QString setupTranslations(QApplication *app)
253279
{
254280
const auto trPath = Translations::translationsDirectoryPath();
@@ -452,18 +478,7 @@ int main(int argc, char **argv)
452478
}
453479

454480
setupLogging(options);
455-
456-
#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
457-
qCDebug(lcMain) << QNetworkInformation::availableBackends().join(QStringLiteral(", "));
458-
if (!QNetworkInformation::loadDefaultBackend()) {
459-
qCWarning(lcMain) << "Failed to load QNetworkInformation";
460-
} else {
461-
qCDebug(lcMain) << "Loaded network information backend:" << QNetworkInformation::instance()->backendName()
462-
<< "supported features:" << QNetworkInformation::instance()->supportedFeatures();
463-
}
464-
#else
465-
qCWarning(lcMain) << "QNetworkInformation is not available";
466-
#endif
481+
loadQNetworkInformationBackend();
467482

468483
platform->setApplication(&app);
469484

0 commit comments

Comments
 (0)