Qt多线程的一些体会
来源:互联网 发布:熔岩灯淘宝 编辑:程序博客网 时间:2024/06/07 06:58
(1) 带后缀-mt的库才是支持多线程的, 例如windows下面的qt-mt320.lib,其他平台libqt-mt
(2)编译问题,要添加QT_THREAD_SUPPORT
(3)针对线程里面而言,
blocking(阻塞的) = synchronous(同步的 )
non-blocking (非阻塞的) = asynchronous(异步的 )
而Qt的signal/slot的事件机制都是基于主程序的线程的,因此所有的事件都是阻塞型的(blocking),也就是说除非你处理完某个slot事件,不然不会有下个事件被触发。
(4)QSocket,QSocketNotifier不能和QThread一起使用
QSocket is for non-blocking IO, it uses some polling like poll() or select() internally and notifies the actual code by emitting signals.
So QSocket is for use with only the event loop thread, for example in a client with only one socket or a server with very few connections.
If you want a threaded approach use QThread and QSocketDevice.
Put one SocketDevice into listening mode and on accept() create a Handler Thread for the socket file descriptor. Use the second QSocketDevice constructor to initialise the Connection's socket device instance.
The server does
bind()
listen()
and
accept()
When accept returns it has the filedescriptor of the connection's socket which you can pass to another QSocketDevice constructor.
The client does connect() to establish the connection.
Both use readBlock/writeBlock/waitForMore to transfer data.
(2)编译问题,要添加QT_THREAD_SUPPORT
(3)针对线程里面而言,
blocking(阻塞的) = synchronous(同步的 )
non-blocking (非阻塞的) = asynchronous(异步的 )
而Qt的signal/slot的事件机制都是基于主程序的线程的,因此所有的事件都是阻塞型的(blocking),也就是说除非你处理完某个slot事件,不然不会有下个事件被触发。
(4)QSocket,QSocketNotifier不能和QThread一起使用
QSocket is for non-blocking IO, it uses some polling like poll() or select() internally and notifies the actual code by emitting signals.
So QSocket is for use with only the event loop thread, for example in a client with only one socket or a server with very few connections.
If you want a threaded approach use QThread and QSocketDevice.
Put one SocketDevice into listening mode and on accept() create a Handler Thread for the socket file descriptor. Use the second QSocketDevice constructor to initialise the Connection's socket device instance.
The server does
bind()
listen()
and
accept()
When accept returns it has the filedescriptor of the connection's socket which you can pass to another QSocketDevice constructor.
The client does connect() to establish the connection.
Both use readBlock/writeBlock/waitForMore to transfer data.
- Qt多线程的一些体会
- ZT:C++Builder的多线程编程中一些体会
- 补上qt多线程的一些东西
- Qt中多线程使用的一些感想
- Qt使用多线程的一些心得
- 一些工作的体会
- Ajax的一些体会
- OnGestureListener的一些体会
- static的一些体会
- 最近的一些体会
- 自己的一些体会
- 编程的一些体会
- OnGestureListener的一些体会
- 最近的一些体会
- GUIskin的一些体会
- 学习的一些体会
- 学习的一些体会
- 上研后的一些体会
- 转载--大内高手—内存管理器(一)
- ASP网站无法显示验证码的解决方法
- 引用并非指针
- 转载--大内高手—共享内存与线程局部存储
- 创建和配置 Servlet
- Qt多线程的一些体会
- 转载--大内高手—常见内存错误
- 资源类网站AJAX
- KMP的字幕用法之調時同步及保存
- 浏览器执行exe文件的探讨
- 转载--大内高手—惯用手法
- 转载--大内高手--调试手段及原理
- 技术分析系列之详解来自Autorun的攻击
- 如何查看已经有的add-in