From 82f9c62a7bdbb04090ab155c53fc21a76ca9969e Mon Sep 17 00:00:00 2001 From: "a.yankovich" Date: Tue, 29 Sep 2020 19:14:18 +0300 Subject: [PATCH] fix --- .../Front/src/correnthostimageprovider.cpp | 53 +++++++++---------- .../Front/src/correnthostimageprovider.h | 10 ++++ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Site/BaseFront/Front/src/correnthostimageprovider.cpp b/Site/BaseFront/Front/src/correnthostimageprovider.cpp index c605b0f..61b359f 100644 --- a/Site/BaseFront/Front/src/correnthostimageprovider.cpp +++ b/Site/BaseFront/Front/src/correnthostimageprovider.cpp @@ -58,40 +58,39 @@ QQuickTextureFactory *AsyncImageResponse::textureFactory() const { } #ifdef Q_OS_WASM -static void *response = nullptr; +void AsyncImageResponse::downloadSucceeded(emscripten_fetch_t *fetch) { + auto resp = static_cast(fetch->userData); + resp->m_image = QImage::fromData(reinterpret_cast(fetch->data), + fetch->numBytes); + + if (resp->m_requestedSize.isValid()) + resp->m_image = resp->m_image.scaled(resp->m_requestedSize); + + emit resp->finished(); + + emscripten_fetch_close(fetch); // Free data associated with the fetch. +}; + +void AsyncImageResponse::downloadFailed(emscripten_fetch_t *fetch) { + + QuasarAppUtils::Params::log(QString("Downloading %0 failed, HTTP failure status code: %1.\n"). + arg(fetch->url).arg(fetch->status), + QuasarAppUtils::Error); + + emscripten_fetch_close(fetch); // Also free data on failure. + + auto resp = static_cast(fetch->userData); + resp->cancel(); +}; #endif + void AsyncImageResponse::run() { #ifdef Q_OS_WASM - response = this; - auto downloadSucceeded = [](emscripten_fetch_t *fetch) { - auto resp = static_cast(response); - resp->m_image = QImage::fromData(reinterpret_cast(fetch->data), - fetch->numBytes); - - if (resp->m_requestedSize.isValid()) - resp->m_image = resp->m_image.scaled(resp->m_requestedSize); - - emit resp->finished(); - - emscripten_fetch_close(fetch); // Free data associated with the fetch. - }; - - auto downloadFailed = [](emscripten_fetch_t *fetch) { - - QuasarAppUtils::Params::log(QString("Downloading %0 failed, HTTP failure status code: %1.\n"). - arg(fetch->url).arg(fetch->status), - QuasarAppUtils::Error); - - emscripten_fetch_close(fetch); // Also free data on failure. - - auto resp = static_cast(response); - resp->cancel(); - }; - emscripten_fetch_attr_t attr; + attr.userData = this; emscripten_fetch_attr_init(&attr); strcpy(attr.requestMethod, "GET"); attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; diff --git a/Site/BaseFront/Front/src/correnthostimageprovider.h b/Site/BaseFront/Front/src/correnthostimageprovider.h index f943b80..2f8ac27 100644 --- a/Site/BaseFront/Front/src/correnthostimageprovider.h +++ b/Site/BaseFront/Front/src/correnthostimageprovider.h @@ -15,6 +15,10 @@ class QNetworkAccessManager; +#ifdef Q_OS_WASM + class emscripten_fetch_t; +#endif + namespace BaseFront { class BASEFRONT_LIBRARYSHARED_EXPORT AsyncImageResponse : public QQuickImageResponse, public QRunnable @@ -33,6 +37,12 @@ private: QImage m_image; QSize m_requestedSize; +private: +#ifdef Q_OS_WASM + + static void downloadSucceeded(emscripten_fetch_t *fetch); + static void downloadFailed(emscripten_fetch_t *fetch); +#endif }; class BASEFRONT_LIBRARYSHARED_EXPORT CorrentHostImageProvider: public QQuickAsyncImageProvider