1

I'm working in a QT complex application that serves HTTP/TCP requests through QT 4.8 slots.

Example module (QT slot):

QString HelloWorld::greet()
{
  return "Hello world...";
}

With this module, we can call our service through either HTTP or TCP request.

I'm adding a new module that needs to synchronously retrieve data from an external HTTP server. For this, I'm using a QEventLoop and QNetworkAccessManager.

The problem happens on the behavior of QEventLoop. I have minimized my problem to this:

bool NewModule::sendRequest()
{
  QEventLoop loop;

  qDebug() << "BEFORE";

  loop.exec();

  qDebug() << "AFTER";
}

When I call this method from entry point X (i.e. doing an HTTP request), the event loop does loop (logs "BEFORE" only), but when calling the same method from entry point Y (i.e. doing a TCP request), the event loop doesn't loop (logs "BEFORE" and "AFTER").

I have no idea why could this different behavior occur. Can someone point me in the right direction?

Thanks

  • 3
    The code you posted is not enough to identify the problem. I guess you connect some signal to `QEventLoop::quit` slot to stop it, if so, which ones? if not, how do you normally stop the loop? – IlBeldus Jul 10 '17 at 16:47
  • Hi IlBeldus. For troubleshooting this issue, I want an infinite loop, which is not happening in scenario "Y". Thanks for your time and help. – User Not Found Jul 10 '17 at 20:08
  • 1
    And you never want `loop.exec();` to run on main thread. And in that case the worker thread with `loop.exec();` must have all the means to finish at request. And you should use `QNetworkAccessManager` signal for getting the request result instead of local event loop. – Alexander V Jul 11 '17 at 22:02

0 Answers0