mirror of
https://github.com/QuasarApp/DocsSite.git
synced 2025-05-06 08:19:35 +00:00
fix
This commit is contained in:
parent
46d7136718
commit
82f9c62a7b
Site/BaseFront/Front/src
@ -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<AsyncImageResponse*>(fetch->userData);
|
||||
resp->m_image = QImage::fromData(reinterpret_cast<const unsigned char*>(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<AsyncImageResponse*>(fetch->userData);
|
||||
resp->cancel();
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
void AsyncImageResponse::run() {
|
||||
|
||||
|
||||
#ifdef Q_OS_WASM
|
||||
response = this;
|
||||
auto downloadSucceeded = [](emscripten_fetch_t *fetch) {
|
||||
auto resp = static_cast<AsyncImageResponse*>(response);
|
||||
resp->m_image = QImage::fromData(reinterpret_cast<const unsigned char*>(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<AsyncImageResponse*>(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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user