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/http') 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 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/http/httpwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/network/http') 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); -- cgit v1.2.3