Add transport info to the QNetworkInformation manual test

Task-number: QTBUG-91023
Change-Id: I0015bc18b0f5c7faf5826a46ee880add09a7b244
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2021-09-23 14:38:18 +02:00
parent 11d2524bc4
commit ce988284c4
2 changed files with 21 additions and 3 deletions

View File

@ -46,6 +46,7 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
using Reachability = QNetworkInformation::Reachability; using Reachability = QNetworkInformation::Reachability;
using TransportMedia = QNetworkInformation::TransportMedia;
public: public:
MainWindow() : QMainWindow(nullptr) MainWindow() : QMainWindow(nullptr)
@ -67,17 +68,25 @@ public slots:
updateText(); updateText();
} }
void updateTransportMedia(TransportMedia newValue)
{
transportMedia = newValue;
updateText();
}
private: private:
void updateText() void updateText()
{ {
QString str = QString str =
QLatin1String("Reachability: %1\nBehind captive portal: %2") QLatin1String("Reachability: %1\nBehind captive portal: %2\nTransport media: %3")
.arg(enumToString(reachability), QStringView(captive ? u"true" : u"false")); .arg(enumToString(reachability), QStringView(captive ? u"true" : u"false"),
enumToString(transportMedia));
label->setText(str); label->setText(str);
} }
QLabel *const label = new QLabel(this); QLabel *const label = new QLabel(this);
Reachability reachability = Reachability::Unknown; Reachability reachability = Reachability::Unknown;
TransportMedia transportMedia = TransportMedia::Unknown;
bool captive = false; bool captive = false;
}; };

View File

@ -47,7 +47,8 @@ int main(int argc, char **argv)
#endif #endif
if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability
| QNetworkInformation::Feature::CaptivePortal)) { | QNetworkInformation::Feature::CaptivePortal
| QNetworkInformation::Feature::TransportMedia)) {
qWarning("Failed to load any backend"); qWarning("Failed to load any backend");
qDebug() << "Backends available:" << QNetworkInformation::availableBackends().join(", "); qDebug() << "Backends available:" << QNetworkInformation::availableBackends().join(", ");
return -1; return -1;
@ -64,16 +65,24 @@ int main(int argc, char **argv)
QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged, QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged,
[&](bool status) { qDebug() << "Updated, behind captive portal:" << status; }); [&](bool status) { qDebug() << "Updated, behind captive portal:" << status; });
QObject::connect(info, &QNetworkInformation::transportMediaChanged,
[&](QNetworkInformation::TransportMedia newMedia) {
qDebug() << "Updated, current transport media:" << newMedia;
});
#ifdef MOBILE #ifdef MOBILE
// Some extra connections to update the window if we're on mobile // Some extra connections to update the window if we're on mobile
QObject::connect(info, &QNetworkInformation::reachabilityChanged, &window, QObject::connect(info, &QNetworkInformation::reachabilityChanged, &window,
&MainWindow::updateReachability); &MainWindow::updateReachability);
QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged, &window, QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged, &window,
&MainWindow::updateCaptiveState); &MainWindow::updateCaptiveState);
QObject::connect(info, &QNetworkInformation::transportMediaChanged, &window,
&MainWindow::updateTransportMedia);
#endif #endif
qDebug() << "Initial reachability:" << info->reachability(); qDebug() << "Initial reachability:" << info->reachability();
qDebug() << "Behind captive portal:" << info->isBehindCaptivePortal(); qDebug() << "Behind captive portal:" << info->isBehindCaptivePortal();
qDebug() << "Transport media:" << info->transportMedia();
return app.exec(); return app.exec();
} }