1
votes

So I have this code:

QUrl url("http://...");
QNetworkRequest request(url);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()), SLOT(onRequestCompleted()));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),SLOT(onError(QNetworkReply::NetworkError)));

and I cant get signal to the other fuction

void IpResolver::onRequestCompleted()
{
QString webContent;

QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

if (reply)
{
    if (reply->error() == QNetworkReply::NoError)
    {
        QString webContent = reply->readAll();
    }
}
}

I cant figure out the solution, help please.

1
Your topic "QNetworkAccessManager does not work" is false. I have used that class many times and while it does have some issues, saying "it does not work" is blatantly false. Saying "I can't figure out how to use it correctly" would be closer to the truth. - Jesper Juhl
okay I am gonna rename it - filcitheking
"Can't get signal to the other function" you mean your slot is never called? - Frank Osterfeld
Yes, slot onRequestComlpleted is never called. - filcitheking

1 Answers

1
votes

I don't know what exactly you want, but:

  1. Why do you use reply pointer instead of some kind onRequestCompleted(QNetworkReply *reply)?
  2. If you do so:

    QUrl url("http://...");
    QNetworkRequest request(url);
    connect(m_networkManager, &QNetworkAccessManager::finished, this, &IpResolver::onRequestCompleted);
    m_networkManager->get(request);
    
  3. And your slot will be, for example:

    void IpResolver::onRequestCompleted(QNetworkReply *reply)
    {
        QString webContent;
        if (reply->error() == QNetworkReply::NoError)
            webContent = reply->readAll();
    }