4

I want to use Asio and Qt together ? each of them have a two method that must be called and each of them are blocking for example : Asio has io_service.run() and qt has QCoreApplication.exec() if I run one of them then another cannot be run.

I have two solutions:

  1. create another thread and call io_service.run() from that.
  2. create a timer with 100ms cycle and call io_service.poll() from same thread that call QCoreApplication.exec().

These solutions are correct?

tshepang
  • 12,111
  • 21
  • 91
  • 136
softghost
  • 1,167
  • 1
  • 10
  • 16
  • Possible duplicate of [How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK](http://stackoverflow.com/questions/1001032/how-to-integrate-boost-asio-main-loop-in-gui-framework-like-qt4-or-gtk) – Alexander Shishenko Jan 19 '17 at 09:41

2 Answers2

2

This is simple solution and works on every platform, but it has some minor drawback. You are introducing latency to asio-part of your application, which may be acceptable or not - depends on your case.

You may be interested in my solution, that makes real integration of asio and QT mainloops.

Look also at the following question for more on this topic: How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK

Community
  • 1
  • 1
peper0
  • 3,111
  • 23
  • 35
0

You definitely want to look into multi-threading your application. Qt helps you out with pretty good platform-independent threading classes. You'll also need to address communication between objects owned by different threads and also will need to bear in mind that painting is limited outside of the GUI thread.

sam-w
  • 7,478
  • 1
  • 47
  • 77
  • No, In this way, Qt use select architecture and I need proactor architecture in Linux kernel 2.6 that Asio has this feature. So this not my question? **I need to use Asio.** sorry for late answer. – softghost Nov 07 '11 at 12:01
  • I understood your question to mean that: You need to use ASIO in your Qt app but were not sure whether/how to multithread it. Apologies for the confusion, but what is your exact question? :) – sam-w Nov 07 '11 at 14:54
  • are my former solutions good? in performance: calling io_service.poll() every 100 ms is a good work? – softghost Nov 08 '11 at 13:27