2020-12-18 14:35:49 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-27 13:56:32 +00:00
|
|
|
#ifdef MOBILE
|
2021-09-20 18:04:24 +00:00
|
|
|
# include "mainwindow.h"
|
|
|
|
# include <QtWidgets/qapplication.h>
|
2021-05-27 13:56:32 +00:00
|
|
|
#else
|
2021-09-20 18:04:24 +00:00
|
|
|
# include <QtCore/qcoreapplication.h>
|
2021-05-27 13:56:32 +00:00
|
|
|
#endif
|
2021-09-20 18:04:24 +00:00
|
|
|
|
2021-02-05 12:16:02 +00:00
|
|
|
#include <QtCore/qdebug.h>
|
2020-12-18 14:35:49 +00:00
|
|
|
#include <QtNetwork/qnetworkinformation.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2021-05-27 13:56:32 +00:00
|
|
|
#ifdef MOBILE
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
MainWindow window;
|
|
|
|
window.show();
|
|
|
|
#else
|
2020-12-18 14:35:49 +00:00
|
|
|
QCoreApplication app(argc, argv);
|
2021-05-27 13:56:32 +00:00
|
|
|
#endif
|
2020-12-18 14:35:49 +00:00
|
|
|
|
2021-10-21 11:07:33 +00:00
|
|
|
// Use the platform-default:
|
2022-02-02 14:27:08 +00:00
|
|
|
if (!QNetworkInformation::loadDefaultBackend()) {
|
2020-12-18 14:35:49 +00:00
|
|
|
qWarning("Failed to load any backend");
|
2021-02-05 12:16:02 +00:00
|
|
|
qDebug() << "Backends available:" << QNetworkInformation::availableBackends().join(", ");
|
2020-12-18 14:35:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
QNetworkInformation *info = QNetworkInformation::instance();
|
2021-02-05 12:16:02 +00:00
|
|
|
qDebug() << "Backend loaded:" << info->backendName();
|
2021-10-21 10:18:41 +00:00
|
|
|
qDebug() << "Supports:" << info->supportedFeatures();
|
2021-02-05 12:16:02 +00:00
|
|
|
qDebug() << "Now you can make changes to the current network connection. Qt should see the "
|
|
|
|
"changes and notify about it.";
|
2020-12-18 14:35:49 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::reachabilityChanged,
|
2021-11-03 13:07:42 +00:00
|
|
|
[](QNetworkInformation::Reachability newStatus) {
|
2021-02-05 12:16:02 +00:00
|
|
|
qDebug() << "Updated:" << newStatus;
|
2020-12-18 14:35:49 +00:00
|
|
|
});
|
|
|
|
|
2021-06-03 11:27:56 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::isBehindCaptivePortalChanged,
|
2021-11-03 13:07:42 +00:00
|
|
|
[](bool status) { qDebug() << "Updated, behind captive portal:" << status; });
|
2021-09-20 18:04:24 +00:00
|
|
|
|
2021-10-05 05:45:46 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::transportMediumChanged,
|
2021-11-03 13:07:42 +00:00
|
|
|
[](QNetworkInformation::TransportMedium newMedium) {
|
2021-10-05 05:45:46 +00:00
|
|
|
qDebug() << "Updated, current transport medium:" << newMedium;
|
2021-09-23 12:38:18 +00:00
|
|
|
});
|
|
|
|
|
2021-10-25 18:23:24 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::isMeteredChanged,
|
|
|
|
[](bool metered) {
|
|
|
|
qDebug() << "Updated, metered:" << metered;
|
|
|
|
});
|
|
|
|
|
2021-05-27 13:56:32 +00:00
|
|
|
#ifdef MOBILE
|
2021-09-20 18:04:24 +00:00
|
|
|
// 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);
|
2021-10-05 05:45:46 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::transportMediumChanged, &window,
|
|
|
|
&MainWindow::updateTransportMedium);
|
2021-10-25 18:23:24 +00:00
|
|
|
QObject::connect(info, &QNetworkInformation::isMeteredChanged, &window,
|
|
|
|
&MainWindow::updateMetered);
|
2021-05-27 13:56:32 +00:00
|
|
|
#endif
|
2021-05-21 14:36:57 +00:00
|
|
|
|
|
|
|
qDebug() << "Initial reachability:" << info->reachability();
|
2021-06-03 11:27:56 +00:00
|
|
|
qDebug() << "Behind captive portal:" << info->isBehindCaptivePortal();
|
2021-10-05 05:45:46 +00:00
|
|
|
qDebug() << "Transport medium:" << info->transportMedium();
|
2021-10-25 18:23:24 +00:00
|
|
|
qDebug() << "Is metered:" << info->isMetered();
|
2020-12-18 14:35:49 +00:00
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|
2021-05-27 13:56:32 +00:00
|
|
|
|
2021-09-20 18:04:24 +00:00
|
|
|
// Include the moc output of the MainWindow from here
|
2021-05-27 13:56:32 +00:00
|
|
|
#ifdef MOBILE
|
2021-09-20 18:04:24 +00:00
|
|
|
# include "moc_mainwindow.cpp"
|
2021-05-27 13:56:32 +00:00
|
|
|
#endif
|