Remove bearer management from remaining network examples
Because bearer management is going away Change-Id: I60439c1714e0350b0f2bbef6afc8d2015886135f Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
parent
22c585f0f9
commit
3742c67041
@ -150,29 +150,6 @@ Client::Client(QWidget *parent)
|
|||||||
|
|
||||||
setWindowTitle(QGuiApplication::applicationDisplayName());
|
setWindowTitle(QGuiApplication::applicationDisplayName());
|
||||||
portLineEdit->setFocus();
|
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]
|
||||||
}
|
}
|
||||||
//! [5]
|
//! [5]
|
||||||
@ -241,30 +218,7 @@ void Client::displayError(QAbstractSocket::SocketError socketError)
|
|||||||
|
|
||||||
void Client::enableGetFortuneButton()
|
void Client::enableGetFortuneButton()
|
||||||
{
|
{
|
||||||
getFortuneButton->setEnabled((!networkSession || networkSession->isOpen()) &&
|
getFortuneButton->setEnabled(!hostCombo->currentText().isEmpty() &&
|
||||||
!hostCombo->currentText().isEmpty() &&
|
|
||||||
!portLineEdit->text().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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ class QLabel;
|
|||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QTcpSocket;
|
class QTcpSocket;
|
||||||
class QNetworkSession;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -77,7 +76,6 @@ private slots:
|
|||||||
void readFortune();
|
void readFortune();
|
||||||
void displayError(QAbstractSocket::SocketError socketError);
|
void displayError(QAbstractSocket::SocketError socketError);
|
||||||
void enableGetFortuneButton();
|
void enableGetFortuneButton();
|
||||||
void sessionOpened();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *hostCombo = nullptr;
|
QComboBox *hostCombo = nullptr;
|
||||||
@ -88,8 +86,6 @@ private:
|
|||||||
QTcpSocket *tcpSocket = nullptr;
|
QTcpSocket *tcpSocket = nullptr;
|
||||||
QDataStream in;
|
QDataStream in;
|
||||||
QString currentFortune;
|
QString currentFortune;
|
||||||
|
|
||||||
QNetworkSession *networkSession = nullptr;
|
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -61,29 +61,7 @@ Server::Server(QWidget *parent)
|
|||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||||
|
|
||||||
QNetworkConfigurationManager manager;
|
initServer();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
|
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());
|
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]
|
//! [0] //! [1]
|
||||||
tcpServer = new QTcpServer(this);
|
tcpServer = new QTcpServer(this);
|
||||||
if (!tcpServer->listen()) {
|
if (!tcpServer->listen()) {
|
||||||
|
@ -58,7 +58,6 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QTcpServer;
|
class QTcpServer;
|
||||||
class QNetworkSession;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -70,14 +69,14 @@ public:
|
|||||||
explicit Server(QWidget *parent = nullptr);
|
explicit Server(QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void sessionOpened();
|
|
||||||
void sendFortune();
|
void sendFortune();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initServer();
|
||||||
|
|
||||||
QLabel *statusLabel = nullptr;
|
QLabel *statusLabel = nullptr;
|
||||||
QTcpServer *tcpServer = nullptr;
|
QTcpServer *tcpServer = nullptr;
|
||||||
QVector<QString> fortunes;
|
QVector<QString> fortunes;
|
||||||
QNetworkSession *networkSession = nullptr;
|
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -53,50 +53,11 @@
|
|||||||
#include "chatdialog.h"
|
#include "chatdialog.h"
|
||||||
|
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtNetwork/QNetworkConfigurationManager>
|
|
||||||
#include <QtNetwork/QNetworkSession>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, 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;
|
ChatDialog dialog;
|
||||||
dialog.show();
|
dialog.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -19,14 +19,11 @@ qtHaveModule(widgets) {
|
|||||||
multicastreceiver \
|
multicastreceiver \
|
||||||
multicastsender
|
multicastsender
|
||||||
|
|
||||||
qtConfig(bearermanagement) {
|
qtConfig(processenvironment): SUBDIRS += network-chat
|
||||||
qtConfig(processenvironment): SUBDIRS += network-chat
|
|
||||||
|
|
||||||
SUBDIRS += \
|
SUBDIRS += \
|
||||||
fortuneclient \
|
fortuneclient \
|
||||||
fortuneserver
|
fortuneserver
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
qtConfig(ssl): SUBDIRS += securesocketclient
|
qtConfig(ssl): SUBDIRS += securesocketclient
|
||||||
qtConfig(dtls): SUBDIRS += secureudpserver secureudpclient
|
qtConfig(dtls): SUBDIRS += secureudpserver secureudpclient
|
||||||
|
Loading…
x
Reference in New Issue
Block a user