diff --git a/tests/manual/qnetworkinformation/CMakeLists.txt b/tests/manual/qnetworkinformation/CMakeLists.txt index 964d48c93fe..899d0aa8761 100644 --- a/tests/manual/qnetworkinformation/CMakeLists.txt +++ b/tests/manual/qnetworkinformation/CMakeLists.txt @@ -6,3 +6,9 @@ qt_internal_add_manual_test(qnetworkinformation Qt::Network Qt::Test ) + +qt_internal_extend_target(qnetworkinformation CONDITION ANDROID OR UIKIT + PUBLIC_LIBRARIES + Qt::Widgets + DEFINES + MOBILE) diff --git a/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp b/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp index 953ae132bf4..ca28018d412 100644 --- a/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp +++ b/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp @@ -26,13 +26,71 @@ ** ****************************************************************************/ +#ifdef MOBILE +#include +#include +#include +#include +#else #include +#endif #include #include +#ifdef MOBILE +template +QString enumToString (const QEnum value) +{ + return QString::fromUtf8(QMetaEnum::fromType().valueToKey(int(value))); +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow() : QMainWindow(nullptr) + { + label = new QLabel(this); + label->setText("hello"); + setCentralWidget(label); + } + + void updateReachability(QNetworkInformation::Reachability newValue) + { + reachability = newValue; + updateText(); + } + + void updateCaptiveState(bool newValue) + { + captive = newValue; + updateText(); + } + +private: + void updateText() + { + QString str = + QLatin1String("Reachability: %1\nBehind captive portal: %2") + .arg(enumToString(reachability), QStringView(captive ? u"true" : u"false")); + label->setText(str); + } + + QLabel *label; + QNetworkInformation::Reachability reachability; + bool captive; +}; +#endif + int main(int argc, char **argv) { +#ifdef MOBILE + QApplication app(argc, argv); + MainWindow window; + window.show(); +#else QCoreApplication app(argc, argv); +#endif if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability)) { qWarning("Failed to load any backend"); @@ -44,13 +102,19 @@ int main(int argc, char **argv) qDebug() << "Now you can make changes to the current network connection. Qt should see the " "changes and notify about it."; QObject::connect(info, &QNetworkInformation::reachabilityChanged, - [](QNetworkInformation::Reachability newStatus) { + [&](QNetworkInformation::Reachability newStatus) { qDebug() << "Updated:" << newStatus; +#ifdef MOBILE + window.updateReachability(newStatus); +#endif }); QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged, - [](bool status) { + [&](bool status) { qDebug() << "Updated, behind captive portal:" << status; +#ifdef MOBILE + window.updateCaptiveState(status); +#endif }); qDebug() << "Initial reachability:" << info->reachability(); @@ -58,3 +122,7 @@ int main(int argc, char **argv) return app.exec(); } + +#ifdef MOBILE +#include "tst_qnetworkinformation.moc" +#endif