From 6d18e4a2b8d82519df177bff5a86a8eca5dae9e6 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 7 Feb 2020 16:43:07 +0300 Subject: Revert "QAbstractSocket: deprecate 'error' member-function" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 94b3dd77f29a00ebbd1efdc66d75f57e1c75b152. The patch fixes ambiguity between a getter and a signal by changing the getter name, but we still have to rename the signal to follow the signals naming convention. Revert the commit to keep the getter as is and change the signal name instead. Change-Id: I0dd60cf1ae9d1bd95beeb8ad58661ca4b1fb63b9 Reviewed-by: Mårten Nordheim Reviewed-by: Thiago Macieira --- examples/network/blockingfortuneclient/fortunethread.cpp | 4 ++-- examples/network/threadedfortuneserver/fortunethread.cpp | 2 +- examples/network/torrent/torrentclient.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/network') diff --git a/examples/network/blockingfortuneclient/fortunethread.cpp b/examples/network/blockingfortuneclient/fortunethread.cpp index 24801436df..67ac7ebfa5 100644 --- a/examples/network/blockingfortuneclient/fortunethread.cpp +++ b/examples/network/blockingfortuneclient/fortunethread.cpp @@ -103,7 +103,7 @@ void FortuneThread::run() //! [6] //! [8] if (!socket.waitForConnected(Timeout)) { - emit error(socket.socketError(), socket.errorString()); + emit error(socket.error(), socket.errorString()); return; } //! [8] //! [11] @@ -115,7 +115,7 @@ void FortuneThread::run() do { if (!socket.waitForReadyRead(Timeout)) { - emit error(socket.socketError(), socket.errorString()); + emit error(socket.error(), socket.errorString()); return; } diff --git a/examples/network/threadedfortuneserver/fortunethread.cpp b/examples/network/threadedfortuneserver/fortunethread.cpp index 2e730c6c8f..ddde5121a3 100644 --- a/examples/network/threadedfortuneserver/fortunethread.cpp +++ b/examples/network/threadedfortuneserver/fortunethread.cpp @@ -65,7 +65,7 @@ void FortuneThread::run() QTcpSocket tcpSocket; //! [1] //! [2] if (!tcpSocket.setSocketDescriptor(socketDescriptor)) { - emit error(tcpSocket.socketError()); + emit error(tcpSocket.error()); return; } //! [2] //! [3] diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 00f46df892..6b11338f42 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -867,7 +867,7 @@ void TorrentClient::removeClient() // Remove the host from our list of known peers if the connection // failed. - if (client->peer() && client->socketError() == QAbstractSocket::ConnectionRefusedError) + if (client->peer() && client->error() == QAbstractSocket::ConnectionRefusedError) d->peers.removeAll(client->peer()); // Remove the client from RateController and all structures. -- cgit v1.2.3 From 86f7d44089138b181642ee22989519f188c75bd5 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sat, 22 Feb 2020 20:26:56 +0200 Subject: Examples: request Android storage permissions when using QStandardPaths http example uses QStandardPaths, on Android permissions might need to be explicitly requested to write the downloaded file. Task-number: QTBUG-80717 Change-Id: Icd377254ad77cac661c5ae37e9081e0463493d8b Reviewed-by: Eskil Abrahamsen Blomfeldt --- examples/network/http/http.pro | 4 ++++ examples/network/http/main.cpp | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'examples/network') diff --git a/examples/network/http/http.pro b/examples/network/http/http.pro index 2f2d3b00ae..f67cd01495 100644 --- a/examples/network/http/http.pro +++ b/examples/network/http/http.pro @@ -1,4 +1,8 @@ QT += network widgets +android: qtHaveModule(androidextras) { + QT += androidextras + DEFINES += REQUEST_PERMISSIONS_ON_ANDROID +} HEADERS += httpwindow.h SOURCES += httpwindow.cpp \ diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp index f126c7846a..1339f2f693 100644 --- a/examples/network/http/main.cpp +++ b/examples/network/http/main.cpp @@ -53,11 +53,30 @@ #include #include "httpwindow.h" +#ifdef REQUEST_PERMISSIONS_ON_ANDROID +#include + +bool requestStoragePermission() { + using namespace QtAndroid; + + QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE"); + const QHash results = requestPermissionsSync(QStringList({permission})); + if (!results.contains(permission) || results[permission] == PermissionResult::Denied) { + qWarning() << "Couldn't get permission: " << permission; + return false; + } + + return true; +} +#endif int main(int argc, char *argv[]) { QApplication app(argc, argv); - +#ifdef REQUEST_PERMISSIONS_ON_ANDROID + if (!requestStoragePermission()) + return -1; +#endif HttpWindow httpWin; const QRect availableSize = httpWin.screen()->availableGeometry(); httpWin.resize(availableSize.width() / 5, availableSize.height() / 5); -- cgit v1.2.3 From cb26a4da69db434d4227bc16e41187f3db93c984 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 7 Feb 2020 17:29:33 +0300 Subject: QAbstractSocket: deprecate 'error' signal, use 'errorOccurred' instead [ChangeLog][Deprecation Notice] QAbstractSocket::error() (the signal) is deprecated; superseded by errorOccurred() Change-Id: I11e9c774d7c6096d1e9b37c451cf0b99188b6aad Reviewed-by: Timur Pocheptsov --- examples/network/doc/src/fortuneclient.qdoc | 6 +++--- examples/network/fortuneclient/client.cpp | 2 +- examples/network/loopback/dialog.cpp | 5 ++--- examples/network/network-chat/client.cpp | 3 +-- examples/network/torrent/peerwireclient.cpp | 4 ++-- examples/network/torrent/torrentclient.cpp | 2 +- examples/network/torrent/torrentserver.cpp | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) (limited to 'examples/network') diff --git a/examples/network/doc/src/fortuneclient.qdoc b/examples/network/doc/src/fortuneclient.qdoc index 544fa156b7..4cb7544fc0 100644 --- a/examples/network/doc/src/fortuneclient.qdoc +++ b/examples/network/doc/src/fortuneclient.qdoc @@ -89,7 +89,7 @@ The only QTcpSocket signals we need in this example are QTcpSocket::readyRead(), signifying that data has been received, and - QTcpSocket::error(), which we will use to catch any connection errors: + QTcpSocket::errorOccurred(), which we will use to catch any connection errors: \dots \snippet fortuneclient/client.cpp 3 @@ -118,11 +118,11 @@ \li \e{An error occurs.} We need to inform the user if the connection failed or was broken. In this case, QTcpSocket will emit - \l{QTcpSocket::error()}{error()}, and \c Client::displayError() will be + \l{QTcpSocket::errorOccurred()}{errorOccurred()}, and \c Client::displayError() will be called. \endlist - Let's go through the \l{QTcpSocket::error()}{error()} case first: + Let's go through the \l{QTcpSocket::errorOccurred()}{errorOccurred()} case first: \snippet fortuneclient/client.cpp 13 diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp index 0ccbf51df8..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::of(&QAbstractSocket::error), + connect(tcpSocket, &QAbstractSocket::errorOccurred, //! [3] this, &Client::displayError); //! [4] diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp index d87f024031..4037f4c085 100644 --- a/examples/network/loopback/dialog.cpp +++ b/examples/network/loopback/dialog.cpp @@ -78,7 +78,7 @@ Dialog::Dialog(QWidget *parent) connect(&tcpClient, &QAbstractSocket::connected, this, &Dialog::startTransfer); connect(&tcpClient, &QIODevice::bytesWritten, this, &Dialog::updateClientProgress); - connect(&tcpClient, QOverload::of(&QAbstractSocket::error), + connect(&tcpClient, &QAbstractSocket::errorOccurred, this, &Dialog::displayError); QVBoxLayout *mainLayout = new QVBoxLayout; @@ -131,8 +131,7 @@ void Dialog::acceptConnection() connect(tcpServerConnection, &QIODevice::readyRead, this, &Dialog::updateServerProgress); - connect(tcpServerConnection, - QOverload::of(&QAbstractSocket::error), + connect(tcpServerConnection, &QAbstractSocket::errorOccurred, this, &Dialog::displayError); connect(tcpServerConnection, &QTcpSocket::disconnected, tcpServerConnection, &QTcpSocket::deleteLater); diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp index d451181813..fe35d535f4 100644 --- a/examples/network/network-chat/client.cpp +++ b/examples/network/network-chat/client.cpp @@ -102,8 +102,7 @@ void Client::newConnection(Connection *connection) { connection->setGreetingMessage(peerManager->userName()); - connect(connection, QOverload::of(&Connection::error), - this, &Client::connectionError); + connect(connection, &Connection::errorOccurred, this, &Client::connectionError); connect(connection, &Connection::disconnected, this, &Client::disconnected); connect(connection, &Connection::readyForUse, this, &Client::readyForUse); } diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp index cea4ef53fa..c30abd0e13 100644 --- a/examples/network/torrent/peerwireclient.cpp +++ b/examples/network/torrent/peerwireclient.cpp @@ -107,8 +107,8 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent) this, &PeerWireClient::readyRead); connect(&socket, &QTcpSocket::disconnected, this, &PeerWireClient::disconnected); - connect(&socket, QOverload::of(&QTcpSocket::error), - this, QOverload::of(&PeerWireClient::error)); + connect(&socket, &QTcpSocket::errorOccurred, + this, &PeerWireClient::errorOccurred); connect(&socket, &QTcpSocket::bytesWritten, this, &PeerWireClient::bytesWritten); connect(&socket, &QTcpSocket::stateChanged, diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 6b11338f42..2ba4476861 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -843,7 +843,7 @@ void TorrentClient::initializeConnection(PeerWireClient *client) this, &TorrentClient::setupOutgoingConnection); connect(client, &PeerWireClient::disconnected, this, &TorrentClient::removeClient); - connect(client, QOverload::of(&PeerWireClient::error), + connect(client, &PeerWireClient::errorOccurred, this, &TorrentClient::removeClient); connect(client, &PeerWireClient::piecesAvailable, this, &TorrentClient::peerPiecesAvailable); diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp index 215498194b..7af958c27c 100644 --- a/examples/network/torrent/torrentserver.cpp +++ b/examples/network/torrent/torrentserver.cpp @@ -80,7 +80,7 @@ void TorrentServer::incomingConnection(qintptr socketDescriptor) if (ConnectionManager::instance()->canAddConnection() && !clients.isEmpty()) { connect(client, &PeerWireClient::infoHashReceived, this, &TorrentServer::processInfoHash); - connect(client, QOverload::of(&PeerWireClient::error), + connect(client, &PeerWireClient::errorOccurred, this, QOverload<>::of(&TorrentServer::removeClient)); RateController::instance()->addSocket(client); ConnectionManager::instance()->addConnection(client); -- cgit v1.2.3 From 4c86e667d220e27bb4b6e370675ffb2872e8521c Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Mon, 10 Feb 2020 12:29:57 +0300 Subject: Revert "QNetworkReply: deprecate the 'error' getter" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ccb2cb84f535b0bfce19a95d7f3a36803480cae8 and commit 0f568d0a671e9f0667a1b47ffa6fbb9f7a10d9f5. The patches fix ambiguity between a getter and a signal by changing the getter name, but we still have to rename the signal to follow the signals naming convention. Revert the commits to keep the getter as is and change the signal name instead. Change-Id: Iddbab7c33eea03826ae7c114a01857ed45bde6db Reviewed-by: Mårten Nordheim --- examples/network/download/main.cpp | 2 +- examples/network/downloadmanager/downloadmanager.cpp | 2 +- examples/network/googlesuggest/googlesuggest.cpp | 2 +- examples/network/http/httpwindow.cpp | 2 +- examples/network/torrent/trackerclient.cpp | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples/network') diff --git a/examples/network/download/main.cpp b/examples/network/download/main.cpp index f496c1723e..076dfdfd0b 100644 --- a/examples/network/download/main.cpp +++ b/examples/network/download/main.cpp @@ -175,7 +175,7 @@ void DownloadManager::sslErrors(const QList &sslErrors) void DownloadManager::downloadFinished(QNetworkReply *reply) { QUrl url = reply->url(); - if (reply->networkError()) { + if (reply->error()) { fprintf(stderr, "Download of %s failed: %s\n", url.toEncoded().constData(), qPrintable(reply->errorString())); diff --git a/examples/network/downloadmanager/downloadmanager.cpp b/examples/network/downloadmanager/downloadmanager.cpp index eceb48977b..cbad29541a 100644 --- a/examples/network/downloadmanager/downloadmanager.cpp +++ b/examples/network/downloadmanager/downloadmanager.cpp @@ -162,7 +162,7 @@ void DownloadManager::downloadFinished() progressBar.clear(); output.close(); - if (currentDownload->networkError()) { + if (currentDownload->error()) { // download failed fprintf(stderr, "Failed: %s\n", qPrintable(currentDownload->errorString())); output.remove(); diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp index 1ae515f530..2cba43178e 100644 --- a/examples/network/googlesuggest/googlesuggest.cpp +++ b/examples/network/googlesuggest/googlesuggest.cpp @@ -209,7 +209,7 @@ void GSuggestCompletion::preventSuggest() void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply) { QUrl url = networkReply->url(); - if (networkReply->networkError() == QNetworkReply::NoError) { + if (networkReply->error() == QNetworkReply::NoError) { QVector choices; QByteArray response(networkReply->readAll()); diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index d0eb2529cd..c7bf0c0dff 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -249,7 +249,7 @@ void HttpWindow::httpFinished() return; } - if (reply->networkError()) { + if (reply->error()) { QFile::remove(fi.absoluteFilePath()); statusLabel->setText(tr("Download failed:\n%1.").arg(reply->errorString())); downloadButton->setEnabled(true); diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index a50a49fd64..264a6cc04c 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -165,8 +165,8 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply) return; } - if (reply->networkError() != QNetworkReply::NoError) { - emit connectionError(reply->networkError()); + if (reply->error() != QNetworkReply::NoError) { + emit connectionError(reply->error()); return; } -- cgit v1.2.3