Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved QNetworckAccessManager & Connecting

    General and Desktop
    2
    5
    887
    Loading More Posts
    • 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.
    • S
      shahriar25 last edited by

      Hi,
      I want to download a list of icons for the items of my QStandardItemModel (appsModel). when I do this it does nothing:

      void MainWindow::downloadIcons()
      {
      for (int i=0; i<appsModel->rowCount(); ++i)
      {
      QUrl iconUrl("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");

          QNetworkRequest request(iconUrl);
      
          QNetworkAccessManager *tempManager = new QNetworkAccessManager;
          tempManager->get(request);
      

      connect(tempManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(setDownloadedIcons(QNetworkReply*)));
      }
      }

      for now the link is the google image but I will set it to the data of items of my model. It's just for testing. what am I doing wrong?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You should also connect the error signal

        By the way, why are you re-creating a new QNetworkAccessManager each time ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • S
          shahriar25 last edited by

          Hi, @SGaist
          My code doesn't work. I can't see how the problem is related to connecting the error signal. can you explain?

          And also What do you mean by one QNetworkAccessManager? How can I do that?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            That would allow you to know that something wrong happened by at least printing the error on the console.

            I mean don't recreate one each time you send a request. Currently you also have a memory leak since you never delete them.

            Just add one as a member of your MainWindow class and use it to send all the requests.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • S
              shahriar25 last edited by

              Hi, thank you the problem is solved

              1 Reply Last reply Reply Quote 0
              • First post
                Last post