QEventLoop slot not called with WASM

248 Views Asked by At

I am trying to run the following code:

std::string RequestLogin()
{
std::cout << ">> User Login method..." << std::endl;
QNetworkRequest request(this->serverUrl);

request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QJsonObject payload;
payload.insert("userName", this->user);
payload.insert("password", this->password);
QByteArray byte_payload = QJsonDocument(payload).toJson();
QEventLoop loop;
bool a = connect(&(this->manager), SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
// send post call
std::cout << "sending the post call" << std::endl;
QNetworkReply *reply = (this->manager).post(request, byte_payload);
loop.exec();
QByteArray reponse = reply->readAll();
std::cout << reponse.toStdString() << std:: endl;

return response.toStdString();
}

This method runs perfectly when I compile it as a c++ file with QT. But I am facing issue while build the wasm and calling this method. The event loop's quit slot is not called and so the response that I am waiting to get is not received. The browser becomes unresponsive. On firefox, when I get notification to kill/wait for the page to respond, if I click kill, then in network tab I see the network rest completed successfully. In the browser window the console did not get the response printed.

Does anybody know how to solve this issue?

For my requirement, I need to create methods in C++ which does some rest call, and on the response I need to do some computation before returning the values to Javascript.

0

There are 0 best solutions below