Pergunta

    m_request.setUrl(pDownloadInfo->url);
    m_preply = pManager->get(m_request);

    QObject::connect(m_preply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(DownloadError(QNetworkReply::NetworkError)));
    QObject::connect(m_preply, SIGNAL(finished()), this, SLOT(ReadyRead()));

I use qt5.0 and I use QNetworkAccessManager to download the http file. I couldn't get the error signal when I input a wrong url which didn't correct, but I can get the finished signal when I input a correct url.

What's reason about this question?

Foi útil?

Solução

QNetworkReply error signal is only for networking layer not protocol layer. It means that it will report all errors that occured during estabilishing connection with HTTP server. When connection is estabilished you won't receive error signal if HTTP server handled it correctly. Even if url you typed produced HTTP errors from 4xx or 5xx status codes still your reply will end without error (network error) as server handled your request.

If you want to handle HTTP errors you must use reply attributes with QNetworkReply::attribute method and handle them separately from errors that were reported with error signal

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top