0

In my application I have a need to block execution until a signal arrives (wait for web request to finish). This happens in a non-gui thread.

Looking at the blocking fortune client example in Qt 5.3 docs, it appears that it uses waitForConnected() method that is specific to the QTcpSocket class, but I am using QNetworkAccessManager which has no wait methods at all.

I have also read elsewhere that to do this one might want to create a temporary QEventLoop, which will block until the events complete. This solution comes with a bunch of warnings that it should not be used in "production code" because of various latent problems that might arrise in corner cases etc.

So. What's a guy to do?

Can I somehow make this work with a QWaitCondition without introducing a second thread? What synchronization primitives exist in Qt5 that would allow me to wait for a signal to arrive in a single thread?

Thanks!

Community
  • 1
  • 1
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • Qt is designed to be asynchronous, meaning you shouldn't have to block except in a few unusual circumstances (unit tests, for example.) If you could describe what you're trying to achieve, perhaps someone could suggest a way to accomplish it without blocking. – MrEricSir Aug 02 '14 at 02:13
  • That sort of answers the question, there are no primitives for blocking on signals in Qt except starting a temporary event-loop. – Mr. Developerdude Aug 04 '14 at 18:49
  • How about making that an answer so we can get this thread out of its missery? – Mr. Developerdude Nov 12 '14 at 04:49

1 Answers1

0

Qt is designed to be asynchronous, meaning you shouldn't have to block except in a few unusual circumstances (unit tests, for example.)

If you could describe what you're trying to achieve, perhaps someone could suggest a way to accomplish it without blocking.

MrEricSir
  • 8,044
  • 4
  • 30
  • 35