Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QNetworckAccessManager & Connecting



  • 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?


  • Lifetime Qt Champion

    Hi,

    You should also connect the error signal

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



  • 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?


  • Lifetime Qt Champion

    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.



  • Hi, thank you the problem is solved


Log in to reply