Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems working with QNetworkAccessManager

Problems working with QNetworkAccessManager

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 714 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Romaniy
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved