问题描述
有什么方法可以将Boost.Asio与Qt4(首选)或GTK主循环集成?GTK提供了像API这样的poll(2),所以技术上应该是可能的。 Qt提供了自己的网络层,但我更愿意使用为Boost.Asio编写的现有代码。
我想在不使用的情况下使用额外的线程将它们集成
是否有任何参考资料如何为Qt4(首选)或GTKmm?
谢谢。
编辑 b
我想澄清几件事情,以使答案更容易。 Qt和GTKmm都提供
select like功能:
,如何将现有的选择器/轮询器作为反应器集成到
Boost.Asio io_service
。今天,Boost.Asio可以使用select,kqueue,epoll,/ dev / poll和iocp作为反应器/ proactor服务。我想将它集成到GUI框架的主循环中。
欢迎任何建议和解决方案(更好)。
这是一个相当古老的问题,但对于那些现在正在阅读的人,我想分享,它是用于boost :: asio的QAbstractEventDispatcher的一个实现。
您只需要在创建QApplication之前添加以下行(通常是在main ))。
QApplication :: setEventDispatcher(new QAsioEventDispatcher(my_io_service));
这会导致io_service与qt应用程序在一个线程中一起运行,而没有额外的延迟和性能(像解决方案中不时调用io_service :: poll())。
不幸的是,我的解决方案仅适用于posix系统,因为它使用asio :: posix :: stream_descriptor。 Windows支持可能需要完全不同的方法或非常相似 - 我不知道。
Is there any way to integrate Boost.Asio with Qt4 (preferred) or GTK main loop?GTK provides poll(2) like API so technically is should be possible. Qt provides its own networking layer, however I prefer to use existing code written for Boost.Asio.I want to integrate them without using an additional thread.
Is there any reference how to do this for Qt4 (preferred) or GTKmm?
Thanks.
Edit
I want to clearify several things to make the answer easier. Both Qt and GTKmm provide"select like" functionality:
- http://qt-project.org/doc/qt-5.0/qtcore/qsocketnotifier.html
- http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__MainLoop.html
So, the question is, how to integrate existing "selectors/pollers" as reactor toBoost.Asio io_service
. Today, Boost.Asio can use select, kqueue, epoll, /dev/poll and iocp as reactor/proactor service. I want to integrate it to the main-loop of GUI framework.
Any suggestions and solutions (better) are welcome.
It's rather old question but for those who are reading it now I would like to share my code which is an implementation of QAbstractEventDispatcher for boost::asio.
All you need is to add the following line before creating QApplication (usually it's in main()).
QApplication::setEventDispatcher(new QAsioEventDispatcher(my_io_service));
It will cause, that io_service is being run together with qt application in one thread without additional latency and performance drop (like in solution with calling io_service::poll() "from time to time").
Unfortunately, my solution is for posix systems only, since it use asio::posix::stream_descriptor . Windows support may need completely different approach or quite similar - I don't really know.
这篇关于如何将Boost.Asio主循环集成到像Qt4或GTK这样的GUI框架中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!