如何正确使用QNetworkReply?我看过这样的例子:

void HttpDownload::on_downloadButton_clicked()
{
    // get url
    url = (ui->urlEdit->text());

    // get() method posts a request
    // to obtain the contents of the target request
    // and returns a new QNetworkReply object
    // opened for reading which emits
    // the readyRead() signal whenever new data arrives.
    reply = manager->get(QNetworkRequest(url));

    // Whenever more data is received from the network,
    // this readyRead() signal is emitted
    connect(reply, SIGNAL(finished()),
            this, SLOT(handleFinish()));
}

建立连接之前是否可能会发出完成的信号?

最佳答案

还检查错误

connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(networkErrorSlot(QNetworkReply::NetworkError)));

我认为在错误情况下也会发出完成信号,并且在建立连接之前看起来好像已经发出完成信号。

关于c++ - Qt:正确使用QNetworkReply吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31744727/

10-11 01:03