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. Multiple requests with QNetworkAccessManager
Qt 6.11 is out! See what's new in the release blog

Multiple requests with QNetworkAccessManager

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    Defohin
    wrote on last edited by Defohin
    #1

    I have a class called NYTimes that class has a method called parse(QVector<QString> addresses, const QString &word), that method will receive a list of addresses. NYTimes is a class that looks for a specific word or tag on the content of a page, for example: Does that article from NYTimes contain a tag or word called sports on it? If yes, then I want to return the address that has the word.

    As you can see on the title I want to create multiple requests cause it's a list of addresses and I don't want to wait each one to download, parse and then return.

    The question is: How to get the list of addresses, download, parse (check for the word), concurrently and then return another QVector<QString> with ONLY the addresses that went right?

    raven-worxR 1 Reply Last reply
    0
    • D Defohin

      I have a class called NYTimes that class has a method called parse(QVector<QString> addresses, const QString &word), that method will receive a list of addresses. NYTimes is a class that looks for a specific word or tag on the content of a page, for example: Does that article from NYTimes contain a tag or word called sports on it? If yes, then I want to return the address that has the word.

      As you can see on the title I want to create multiple requests cause it's a list of addresses and I don't want to wait each one to download, parse and then return.

      The question is: How to get the list of addresses, download, parse (check for the word), concurrently and then return another QVector<QString> with ONLY the addresses that went right?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Defohin said in Multiple requests with QNetworkAccessManager:

      s a method called parse(QVector<QString> addresses, const QString &word), that method will receive a list of addresses. NYTimes is a class that looks for a specific word or tag on the content of a p

      connect a slot to the QNetworkAccessManagers::finished(QNetworkReply*) signal. Check for errors and parse the reply. If it contains the word add the reply->url() to a list.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Defohin
        wrote on last edited by
        #3

        As I have a QVector I have to use foreach, do I have to connect all the QNetworkAccessManager::get to the same finished slot?

        raven-worxR 1 Reply Last reply
        0
        • D Defohin

          As I have a QVector I have to use foreach, do I have to connect all the QNetworkAccessManager::get to the same finished slot?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Defohin
          you should something like this:

          QNetworkAccessManager* nam = new QNetworkAccessManager( this );
          connect( nam, &QNetworkAccessManager::finished, this, &NYTimes::onReplyFinished )
          foreach( QString address, addresses )
          {
               nam->get( address );
          }
          ....
          void NYTimes::onReplyFinished( QNetworkReply* reply )
          {
                  switch( reply->error() )
                  {
                           case QNetworkReply::NoError:
                                        // parse reply->readAll();
                                 break;
                          case QNetworkReply::XXX:
                                        //error handling
                                 break;
                 }
          }
          

          Do you use a recent compiler (C++11)?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Defohin
            wrote on last edited by
            #5

            Yes, I'm using VS2015

            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