From 3742c67041b47adefa0d293e45d543f31ab15da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 14 Feb 2020 16:35:01 +0100 Subject: Remove bearer management from remaining network examples Because bearer management is going away Change-Id: I60439c1714e0350b0f2bbef6afc8d2015886135f Reviewed-by: Timur Pocheptsov Reviewed-by: Paul Wicking --- examples/network/fortuneclient/client.cpp | 48 +------------------------------ examples/network/fortuneclient/client.h | 4 --- examples/network/fortuneserver/server.cpp | 41 ++------------------------ examples/network/fortuneserver/server.h | 5 ++-- examples/network/network-chat/main.cpp | 39 ------------------------- examples/network/network.pro | 11 +++---- 6 files changed, 9 insertions(+), 139 deletions(-) (limited to 'examples/network') diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp index 4d3a318a7b..0ccbf51df8 100644 --- a/examples/network/fortuneclient/client.cpp +++ b/examples/network/fortuneclient/client.cpp @@ -150,29 +150,6 @@ Client::Client(QWidget *parent) setWindowTitle(QGuiApplication::applicationDisplayName()); portLineEdit->setFocus(); - - QNetworkConfigurationManager manager; - if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { - // Get saved network configuration - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); - settings.endGroup(); - - // If the saved network configuration is not currently discovered use the system default - QNetworkConfiguration config = manager.configurationFromIdentifier(id); - if ((config.state() & QNetworkConfiguration::Discovered) != - QNetworkConfiguration::Discovered) { - config = manager.defaultConfiguration(); - } - - networkSession = new QNetworkSession(config, this); - connect(networkSession, &QNetworkSession::opened, this, &Client::sessionOpened); - - getFortuneButton->setEnabled(false); - statusLabel->setText(tr("Opening network session.")); - networkSession->open(); - } //! [5] } //! [5] @@ -241,30 +218,7 @@ void Client::displayError(QAbstractSocket::SocketError socketError) void Client::enableGetFortuneButton() { - getFortuneButton->setEnabled((!networkSession || networkSession->isOpen()) && - !hostCombo->currentText().isEmpty() && + getFortuneButton->setEnabled(!hostCombo->currentText().isEmpty() && !portLineEdit->text().isEmpty()); } - -void Client::sessionOpened() -{ - // Save the used configuration - QNetworkConfiguration config = networkSession->configuration(); - QString id; - if (config.type() == QNetworkConfiguration::UserChoice) - id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); - else - id = config.identifier(); - - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); - settings.endGroup(); - - statusLabel->setText(tr("This examples requires that you run the " - "Fortune Server example as well.")); - - enableGetFortuneButton(); -} - diff --git a/examples/network/fortuneclient/client.h b/examples/network/fortuneclient/client.h index ac335acb83..80177bacbf 100644 --- a/examples/network/fortuneclient/client.h +++ b/examples/network/fortuneclient/client.h @@ -61,7 +61,6 @@ class QLabel; class QLineEdit; class QPushButton; class QTcpSocket; -class QNetworkSession; QT_END_NAMESPACE //! [0] @@ -77,7 +76,6 @@ private slots: void readFortune(); void displayError(QAbstractSocket::SocketError socketError); void enableGetFortuneButton(); - void sessionOpened(); private: QComboBox *hostCombo = nullptr; @@ -88,8 +86,6 @@ private: QTcpSocket *tcpSocket = nullptr; QDataStream in; QString currentFortune; - - QNetworkSession *networkSession = nullptr; }; //! [0] diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp index 7db81fe07a..c91b6a5c0c 100644 --- a/examples/network/fortuneserver/server.cpp +++ b/examples/network/fortuneserver/server.cpp @@ -61,29 +61,7 @@ Server::Server(QWidget *parent) setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); - QNetworkConfigurationManager manager; - if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { - // Get saved network configuration - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); - settings.endGroup(); - - // If the saved network configuration is not currently discovered use the system default - QNetworkConfiguration config = manager.configurationFromIdentifier(id); - if ((config.state() & QNetworkConfiguration::Discovered) != - QNetworkConfiguration::Discovered) { - config = manager.defaultConfiguration(); - } - - networkSession = new QNetworkSession(config, this); - connect(networkSession, &QNetworkSession::opened, this, &Server::sessionOpened); - - statusLabel->setText(tr("Opening network session.")); - networkSession->open(); - } else { - sessionOpened(); - } + initServer(); //! [2] fortunes << tr("You've been leading a dog's life. Stay off the furniture.") @@ -128,23 +106,8 @@ Server::Server(QWidget *parent) setWindowTitle(QGuiApplication::applicationDisplayName()); } -void Server::sessionOpened() +void Server::initServer() { - // Save the used configuration - if (networkSession) { - QNetworkConfiguration config = networkSession->configuration(); - QString id; - if (config.type() == QNetworkConfiguration::UserChoice) - id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); - else - id = config.identifier(); - - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); - settings.endGroup(); - } - //! [0] //! [1] tcpServer = new QTcpServer(this); if (!tcpServer->listen()) { diff --git a/examples/network/fortuneserver/server.h b/examples/network/fortuneserver/server.h index c5bfa7d928..96d7145148 100644 --- a/examples/network/fortuneserver/server.h +++ b/examples/network/fortuneserver/server.h @@ -58,7 +58,6 @@ QT_BEGIN_NAMESPACE class QLabel; class QTcpServer; -class QNetworkSession; QT_END_NAMESPACE //! [0] @@ -70,14 +69,14 @@ public: explicit Server(QWidget *parent = nullptr); private slots: - void sessionOpened(); void sendFortune(); private: + void initServer(); + QLabel *statusLabel = nullptr; QTcpServer *tcpServer = nullptr; QVector fortunes; - QNetworkSession *networkSession = nullptr; }; //! [0] diff --git a/examples/network/network-chat/main.cpp b/examples/network/network-chat/main.cpp index f88e29977b..029c18f0ff 100644 --- a/examples/network/network-chat/main.cpp +++ b/examples/network/network-chat/main.cpp @@ -53,50 +53,11 @@ #include "chatdialog.h" #include -#include -#include int main(int argc, char *argv[]) { QApplication app(argc, argv); - QNetworkConfigurationManager manager; - if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { - // Get saved network configuration - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); - settings.endGroup(); - - // If the saved network configuration is not currently discovered use the system default - QNetworkConfiguration config = manager.configurationFromIdentifier(id); - if ((config.state() & QNetworkConfiguration::Discovered) != - QNetworkConfiguration::Discovered) { - config = manager.defaultConfiguration(); - } - - QNetworkSession *networkSession = new QNetworkSession(config, &app); - networkSession->open(); - networkSession->waitForOpened(); - - if (networkSession->isOpen()) { - // Save the used configuration - QNetworkConfiguration config = networkSession->configuration(); - QString id; - if (config.type() == QNetworkConfiguration::UserChoice) { - id = networkSession->sessionProperty( - QLatin1String("UserChoiceConfiguration")).toString(); - } else { - id = config.identifier(); - } - - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("QtNetwork")); - settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); - settings.endGroup(); - } - } - ChatDialog dialog; dialog.show(); return app.exec(); diff --git a/examples/network/network.pro b/examples/network/network.pro index 7b6271e954..3f851d7c71 100644 --- a/examples/network/network.pro +++ b/examples/network/network.pro @@ -19,14 +19,11 @@ qtHaveModule(widgets) { multicastreceiver \ multicastsender - qtConfig(bearermanagement) { - qtConfig(processenvironment): SUBDIRS += network-chat + qtConfig(processenvironment): SUBDIRS += network-chat - SUBDIRS += \ - fortuneclient \ - fortuneserver - - } + SUBDIRS += \ + fortuneclient \ + fortuneserver qtConfig(ssl): SUBDIRS += securesocketclient qtConfig(dtls): SUBDIRS += secureudpserver secureudpclient -- cgit v1.2.3