Should I connect to QNetworkReply::error() as well?

不羁的心 提交于 2019-12-06 08:50:23
evilruff

Qt documentation states:

void QNetworkReply::error(QNetworkReply::NetworkError code) [signal]

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

From what I've seen in Qt sources (was checking absolutely same issue recently), everywhere after error(), there is a finished() call afterwards. In 5.1.0 I haven't found a place where error is not followed by finished()

for example

void QNetworkReplyImpl::close()
{
    Q_D(QNetworkReplyImpl);
    if (d->state == QNetworkReplyImplPrivate::Aborted ||
        d->state == QNetworkReplyImplPrivate::Finished)
        return;

    // stop the download
    if (d->backend)
        d->backend->closeDownstreamChannel();
    if (d->copyDevice)
        disconnect(d->copyDevice, 0, this, 0);

    QNetworkReply::close();

    // call finished which will emit signals
    d->error(OperationCanceledError, tr("Operation canceled"));
    d->finished();
}

The documentation for error() says, "the finished() signal will probably follow", so no, finished() ought to be sufficient. Don't forget to check the error() getter in the signal handler, though.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!