Qt多线程的一些体会

(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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值