diff options
Diffstat (limited to 'examples/network/fortuneclient/client.cpp')
-rw-r--r-- | examples/network/fortuneclient/client.cpp | 50 |
1 files changed, 2 insertions, 48 deletions
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp index 4d3a318a7b..2daac33c2b 100644 --- a/examples/network/fortuneclient/client.cpp +++ b/examples/network/fortuneclient/client.cpp @@ -121,7 +121,7 @@ Client::Client(QWidget *parent) //! [2] //! [3] connect(tcpSocket, &QIODevice::readyRead, this, &Client::readFortune); //! [2] //! [4] - connect(tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), + connect(tcpSocket, &QAbstractSocket::errorOccurred, //! [3] this, &Client::displayError); //! [4] @@ -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(); -} - |