开发者

explicitly listening for signals

开发者 https://www.devze.com 2023-03-21 03:26 出处:网络
I\'m new 开发者_如何学Pythonto Qt, but I have some experience in C and Java. I\'m trying to write a program that makes multiple TCP connections to different servers on the network.

I'm new 开发者_如何学Pythonto Qt, but I have some experience in C and Java. I'm trying to write a program that makes multiple TCP connections to different servers on the network. the ip's are read in from a text file and i use connectToHost to establish a connection then the socket is added to a QList. this happens in a loop.

the problem is that i only start receiving the connected() signals when the program exits the loop, this causes some unexpected behaviour. so is there a way to poll for signals in the loop?


call QCoreApplication::processEvents() inside your loop to avoid freezing


You can use QAbstractSocket::waitForConnected()

http://doc.qt.io/qt-5/qabstractsocket.html#waitForConnected

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号