diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-02-28 08:40:53 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-02-28 09:48:30 +0100 |
commit | a450cce6b670dbcac84fcc4a66fc632b31ce8414 (patch) | |
tree | 35b77fa22c4def97b619bd3a87f6d394e452bb2e /examples/network/http | |
parent | f6f6eab89f57fb0db8f623f4a92a7b9c4ba6e9ea (diff) | |
parent | 4c86e667d220e27bb4b6e370675ffb2872e8521c (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I469b0501cc65fc5ce4d797a69ae89405cc69c7f8
Diffstat (limited to 'examples/network/http')
-rw-r--r-- | examples/network/http/CMakeLists.txt | 10 | ||||
-rw-r--r-- | examples/network/http/http.pro | 4 | ||||
-rw-r--r-- | examples/network/http/httpwindow.cpp | 2 | ||||
-rw-r--r-- | examples/network/http/main.cpp | 21 |
4 files changed, 35 insertions, 2 deletions
diff --git a/examples/network/http/CMakeLists.txt b/examples/network/http/CMakeLists.txt index 3ce82d63da..d9f50f5c9d 100644 --- a/examples/network/http/CMakeLists.txt +++ b/examples/network/http/CMakeLists.txt @@ -28,6 +28,16 @@ target_link_libraries(http PUBLIC Qt::Widgets ) +if(ANDROID AND TARGET Qt::AndroidExtras) + target_compile_definitions(http PUBLIC + REQUEST_PERMISSIONS_ON_ANDROID + ) + + target_link_libraries(http PUBLIC + Qt::AndroidExtras + ) +endif() + install(TARGETS http RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 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/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/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 <QScreen> #include "httpwindow.h" +#ifdef REQUEST_PERMISSIONS_ON_ANDROID +#include <QtAndroid> + +bool requestStoragePermission() { + using namespace QtAndroid; + + QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE"); + const QHash<QString, PermissionResult> 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); |