@@ -249,6 +249,32 @@ void setupLogging(const CommandLineOptions &options)
249
249
qCInfo (lcMain) << " Arguments:" << qApp->arguments ();
250
250
}
251
251
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
+
252
278
QString setupTranslations (QApplication *app)
253
279
{
254
280
const auto trPath = Translations::translationsDirectoryPath ();
@@ -452,18 +478,7 @@ int main(int argc, char **argv)
452
478
}
453
479
454
480
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 ();
467
482
468
483
platform->setApplication (&app);
469
484
0 commit comments