简体   繁体   中英

Bytes written with QTcpSocket::write has not been received by server when Main Thread running in infinite loop?

I am working on an application, which interacts with server.

while starting, it is loading some data from database, when database size is large then application is running in very long loop let say i have 10 lac records in db and loop will iterate 10 lac times.

After a regular interval of time (set by user) let say 1 seconds, my application is sending heartbeat message to server in different thread.

In normal cases, it is working fine but when application runs in long loop, heartbeat message has not been received by server although written bytes returned by QTcpSocket::write() are same what i am writing (successful), but tcpDump is not showing any byte received.

i have used

tcpSocket->setSocketOption(QAbstractSocket::LowDelayOption , 1); 
tcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption , 600);

Try adding processEvents() inside your loop (let's say every 1000th cycle or every 100ms) to keep your application responsive. Of course, it's a sign of bad design if you encounter such problems. Consider re-design you application to use multiple threads, ie the main thread and a worker thread for long operations (your loop). More about thread support on Qt can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM