返回信息流论坛没有QT版,就直接在这里问了啊~
主线程创建一个子线程check用来周期发起tcp连接,为了可以同时与多台主机通信,在此子线程check中又同时创建多个子线程。
在每个子线程中实例化一个对象qtcp,在此对象qtcp中创建QTcpSocket并与其他主机进行通信,在qtcp的构造函数中完成connected()、readyread()等信号的连接,connect函数的返回值均为true。
但是,此时readyread信号总是无法触发,可以确定的是QTcpSocket的connected()信号确实触发了并执行了相应的槽函数,这是什么原因呢?求大神解答~欲哭无泪啊。
ps:当在主线程中实例化这个对象并创建QTcpSocket时,是可以正常触发readyread()信号的,是不是因为在子线程中的原因呢?QTcpSocket在子线程中创建会受影响吗?求助啊~实在是没办法啊~
这是一条镜像帖。来源:北邮人论坛 / cpp / #87895同步于 2015/7/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
QTcpSocket readyread() 信号无法触发
lwj
2015/7/13镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
你自己建的线程没有事件循环的话你得用别的函数:
This allows QIODevice subclasses to be used without an event loop, or in a separate thread:
waitForReadyRead() - This function suspends operation in the calling thread until new data is available for reading.
waitForBytesWritten() - This function suspends operation in the calling thread until one payload of data has been written to the device.
waitFor....() - Subclasses of QIODevice implement blocking functions for device-specific operations. For example, QProcess has a function called waitForStarted() which suspends operation in the calling thread until the process has started.