1

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ronak SHAH
  • 171
  • 2
  • 11
  • @eyllanesc, then how to achieve synchronous behavior for the web-assembly? – Ronak SHAH Aug 04 '20 at 04:53
  • I found in the documentation of QT, that for console application, nesting event loop is not allowed for emscripten. This is a major limitation. Is there any alternative for it? – Ronak SHAH Sep 08 '20 at 05:19

0 Answers0