tcpserver的读取槽函数如下:
recBuffer.append(tcpSocket->readAll());///>缓存接收的数据
tcpSocket->flush();
我在此处写了一个调用了一下flush函数,但是这个是没有必要的,试看官方文档描述如下:
This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned.
Call this function if you need QAbstractSocket to start sending buffered data immediately. The number of bytes successfully written depends on the operating system. In most cases, you do not need to call this function, because QAbstractSocket will start sending data automatically once control goes back to the event loop. In the absence of an event loop, call waitForBytesWritten() instead.
翻译如下:
博客分析了在QT的TCP服务器读取槽函数中使用flush()函数的情况。官方文档指出,flush()主要用于立即发送缓冲数据,通常在没有事件循环时使用或发送数据时调用,而在接收端槽函数中调用是不必要的。
订阅专栏 解锁全文
1万+

被折叠的 条评论
为什么被折叠?



