Problems working with QNetworkAccessManager

  • Hello everyone!

    I have such situation :
    I need get http request, wait until request totally download whole information to reply and after that analyze this answer in the same function. Is it possible? And if possible, how I can do that?

    Example of code:

    @int login_check(QString login, QString pass)
    QNetworkAccessManager* manager;

    QNetworkReply* reply = manager->get(QNetworkRequest(QUrl("some_host/some_path&login&pass")));
    //I need to wait and only after reply has finished do the next
    if(reply->isFinished()) { 
         //do something with reply->readAll();
     } else {
         //do something else with reply->readAll();
    //continue this function according to reply 


    Thanks for response!

  • You're trying to use an uninitialized QNetworkAccessManager instance.

    I'd recommend against trying to come up with (complicated) setups that allow you to wait for a network reply and then continue your code. It's really not designed that way, it is designed for asynchronous use. That is a Good Thing (TM), as networks may be slow and unreliable, so you will need to deal with that.

    Having said that: if you are on Qt 5.x and you use C++/11, then perhaps you can use a lambda instead. That will get you quite close to what you are looking for.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.