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:
parent
11d2524bc4
commit
ce988284c4
@ -46,6 +46,7 @@ class MainWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
using Reachability = QNetworkInformation::Reachability;
|
||||
using TransportMedia = QNetworkInformation::TransportMedia;
|
||||
|
||||
public:
|
||||
MainWindow() : QMainWindow(nullptr)
|
||||
@ -67,17 +68,25 @@ public slots:
|
||||
updateText();
|
||||
}
|
||||
|
||||
void updateTransportMedia(TransportMedia newValue)
|
||||
{
|
||||
transportMedia = newValue;
|
||||
updateText();
|
||||
}
|
||||
|
||||
private:
|
||||
void updateText()
|
||||
{
|
||||
QString str =
|
||||
QLatin1String("Reachability: %1\nBehind captive portal: %2")
|
||||
.arg(enumToString(reachability), QStringView(captive ? u"true" : u"false"));
|
||||
QLatin1String("Reachability: %1\nBehind captive portal: %2\nTransport media: %3")
|
||||
.arg(enumToString(reachability), QStringView(captive ? u"true" : u"false"),
|
||||
enumToString(transportMedia));
|
||||
label->setText(str);
|
||||
}
|
||||
|
||||
QLabel *const label = new QLabel(this);
|
||||
Reachability reachability = Reachability::Unknown;
|
||||
TransportMedia transportMedia = TransportMedia::Unknown;
|
||||
bool captive = false;
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,8 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability
|
||||
| QNetworkInformation::Feature::CaptivePortal)) {
|
||||
| QNetworkInformation::Feature::CaptivePortal
|
||||
| QNetworkInformation::Feature::TransportMedia)) {
|
||||
qWarning("Failed to load any backend");
|
||||
qDebug() << "Backends available:" << QNetworkInformation::availableBackends().join(", ");
|
||||
return -1;
|
||||
@ -64,16 +65,24 @@ int main(int argc, char **argv)
|
||||
QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged,
|
||||
[&](bool status) { qDebug() << "Updated, behind captive portal:" << status; });
|
||||
|
||||
QObject::connect(info, &QNetworkInformation::transportMediaChanged,
|
||||
[&](QNetworkInformation::TransportMedia newMedia) {
|
||||
qDebug() << "Updated, current transport media:" << newMedia;
|
||||
});
|
||||
|
||||
#ifdef MOBILE
|
||||
// Some extra connections to update the window if we're on mobile
|
||||
QObject::connect(info, &QNetworkInformation::reachabilityChanged, &window,
|
||||
&MainWindow::updateReachability);
|
||||
QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged, &window,
|
||||
&MainWindow::updateCaptiveState);
|
||||
QObject::connect(info, &QNetworkInformation::transportMediaChanged, &window,
|
||||
&MainWindow::updateTransportMedia);
|
||||
#endif
|
||||
|
||||
qDebug() << "Initial reachability:" << info->reachability();
|
||||
qDebug() << "Behind captive portal:" << info->isBehindCaptivePortal();
|
||||
qDebug() << "Transport media:" << info->transportMedia();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user