QTcpSocket::waitForReadyRead超时信号
由于Qt的信号和槽是qt非常好的一个机制,所以Qt的函数中使用了大量的信号和槽。所以在使用的时候一定要注意莫些情况下是否会触发信号。
如一个看起来不会触发信号的函数,文档没有直接说明会产生error信号:
[override virtual] bool QAbstractSocket::waitForReadyRead(int msecs =
30000) Reimplemented from QIODevice::waitForReadyRead(). This function
blocks until new data is available for reading and the readyRead()
signal has been emitted. The function will timeout after msecs
milliseconds; the default timeout is 30000 milliseconds. The function
returns true if the readyRead() signal is emitted and there is new
data available for reading; otherwise it returns false (if an error
occurred or the operation timed out). Note: This function may fail
randomly on Windows. Consider using the event loop and the readyRead()
signal if your software will run on Windows. See also
waitForBytesWritten().
事实上,在超时的时候会触发error(QAbstractSocket::SocketError)信号(SocketTimeoutError),一不注意可能就会产生一个bug
像QListWidget::setCurrentRow(int row),其它的setIndex一些界面选中函数,可能也会产生信号