Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
None
-
6.4.1, 6.5.1
-
None
-
Tested on Chrome 108.0.5359.98 (linux) and Firefox 108.0 (linux)
-
-
f2f2b6ef18907a76461b54e110618e7840971fa7
Description
I'm aware that threading is not officially supported on WebAssembly, but I hope that this bug report will help to stabilize and start supporting it
In my code, I never receive the QNetworkReply::finished signal, when sending a QNetworkRequest via QNetworkAccessManager in a thread on WebAssembly. I verified, that everything with the HTTP headers is set up correctly using a threaded compilation without actually starting a thread (it doesn't load if the headers are wrong).
I've built Qt from source using the following parameters:
../Src/configure -qt-host-path ../gcc_64 -platform wasm-emscripten -submodules qtbase -no-dbus -prefix $PWD/qtbase -feature-thread -opengles3 -c++std 20 -static -optimize-size
cmake --build . -t qtbase
Here is a minimal example:
#include <QCoreApplication> #include <QThread> #include <QTimer> #include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkReply> int main(int argc, char *argv[]) { //////////////////////// works //////////////////////// // qDebug() << "Threaded without a thread"; // QCoreApplication a(argc, argv); // const auto* a_ptr = &a; // QNetworkAccessManager nam; // QNetworkReply* reply = nam.get(QNetworkRequest(QUrl("https://myurl.blah/file.dat"))); // QObject::connect(reply, &QNetworkReply::finished, [reply]() { // const auto url = reply->url(); // const auto error = reply->error(); // if (error == QNetworkReply::NoError) { // qDebug() << "Loading of " << url << " successful."; // } else { // qDebug() << "Loading of " << url << " failed: " << error; // } // reply->deleteLater(); // }); // return a.exec(); //////////////////////// never prints "Na Bumm!" //////////////////////// qDebug() << "Threaded with a thread"; QCoreApplication a(argc, argv); const auto* a_ptr = &a; QThread thread; QNetworkAccessManager nam; const auto& nam_ptr = &nam; nam.moveToThread(&thread); QTimer::singleShot(0, &nam, [nam_ptr]() { QNetworkReply* reply = nam_ptr->get(QNetworkRequest(QUrl("https://myurl.blah/file.dat"))); QObject::connect(reply, &QNetworkReply::finished, [reply]() { qDebug() << "Na bumm!"; const auto url = reply->url(); const auto error = reply->error(); if (error == QNetworkReply::NoError) { qDebug() << "Loading of " << url << " successful."; } else { qDebug() << "Loading of " << url << " failed: " << error; } reply->deleteLater(); }); }); thread.start(); return a.exec(); }
and the cmake file:
cmake_minimum_required(VERSION 3.14) project(qt_test LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network) add_executable(qt_test main.cpp ) target_link_libraries(qt_test Qt${QT_VERSION_MAJOR}::Core Qt6::Network) install(TARGETS qt_test LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})