Switch QNetworkInformation manual test back to using qDebug

It turns out QTextStream on Android isn't as easily visible as it is
when going through qDebug (where it can easily be seen with
`adb logcat -v brief libqnetworkinformation_<arch>.so:* -s`)

Change-Id: I3b495d7a3d331fda6cfe602c461107dd1d0b3faf
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 677797929d8080199990d741773832f80a654265)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2021-02-05 13:16:02 +01:00 committed by Qt Cherry-pick Bot
parent 584541c7e4
commit fcb9a94f83

View File

@ -27,37 +27,28 @@
****************************************************************************/
#include <QtCore/qcoreapplication.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qdebug.h>
#include <QtNetwork/qnetworkinformation.h>
QByteArray nameOfEnumValue(QNetworkInformation::Reachability reachability)
{
return QMetaEnum::fromType<QNetworkInformation::Reachability>().valueToKey(int(reachability));
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QTextStream writer(stdout);
if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability)) {
qWarning("Failed to load any backend");
writer << "Backends available: " << QNetworkInformation::availableBackends().join(", ") << '\n';
qDebug() << "Backends available:" << QNetworkInformation::availableBackends().join(", ");
return -1;
}
QNetworkInformation *info = QNetworkInformation::instance();
writer << "Backend loaded: " << info->backendName() << '\n';
writer << "Now you can make changes to the current network connection. Qt should see the "
"changes and notify about it.\n";
qDebug() << "Backend loaded:" << info->backendName();
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,
[&writer](QNetworkInformation::Reachability newStatus) {
writer << "Updated: " << nameOfEnumValue(newStatus) << '\n';
writer.flush();
[](QNetworkInformation::Reachability newStatus) {
qDebug() << "Updated:" << newStatus;
});
writer << "Initial: " << nameOfEnumValue(info->reachability()) << '\n';
writer.flush();
qDebug() << "Initial:" << info->reachability();
return app.exec();
}