QNetworkReply 是否总是发出 finished()?

Does QNetworkReply always emit finished()?

我看了 signal finished() 的文档,它没有说 finished() 总是发出。我读了 error() 信号:

void QNetworkReply::error(QNetworkReply::NetworkError code) This signal is emitted when the reply detects an error in processing. The finished() signal will probably follow, indicating that the connection is over.

The code parameter contains the code of the error that was detected. Call errorString() to obtain a textual representation of the error condition.

Note: Do not delete the object in the slot connected to this signal. Use deleteLater().

See also error() and errorString().

The finished() signal will probably follow 是否意味着,在某些情况下,QNetworkReply 不会发出 finished() ?

对于 QNetworkReply 错误信号,我们当然可以预期错误代码并不意味着连接中断。例如:

QNetworkReply::ContentNotFoundError 203 the remote content was not found at the server (similar to HTTP error 404)

上面的情况肯定还没有连接完成。没有发出结束信号。

QNetworkReply::RemoteHostClosedError 2 the remote server closed the connection prematurely, before the entire reply was received and processed

到此连接肯定结束了。并发出结束信号。