Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Simple:</strong> Build a QT slot that calls the <code>io_service::poll_one()</code> belonging to the gui. Connect that slot to QT's <code>tick</code> signal.</p> <p><strong>In Depth:</strong> Luckily for you Boost.Asio is very well designed. There are many options on how to provide a thread of execution to the underlying asynchronous internals. People have already mention using <code>io_service::run()</code>, a blocking call with many disadvantages.</p> <p>You are only allowed to access gui widgets from a single thread. External threads generally need to post events to the gui if they want to do mutate any widget. This is very similar to how Asio works.</p> <p>The naive approach is to just dedicate one thread (or timer) to running <code>io_service::run()</code> and have the Asio completion handler post a gui signal. This <em>will</em> work.</p> <p>Instead you can use the guarantee that completion handlers will only be called in the thread of execution of the <code>io_service</code> caller. Don't have the gui thread call <code>io_service::run()</code> as it is blocking and could hang the gui. Instead use <code>io_service::poll()</code> or <code>io_service::poll_one()</code>. This will cause any pending Asio completion handlers to be called from the gui thread. Since the handlers are running in the gui thread they are free to modify the widgets.</p> <p>Now you need make sure the <code>io_service</code> gets a chance to run regularly. I recommend having a repeating gui signal call <code>poll_one()</code> a few times. I believe QT has a tick signal that would do the trick. You could of course roll your own QT signal for more control.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload