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. Getting two QNetworkReply after request

Getting two QNetworkReply after request

Scheduled Pinned Locked Moved General and Desktop
qnetworkaccessmqnetworkreply
1 Posts 1 Posters 695 Views 1 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.
  • David.GD Offline
    David.GD Offline
    David.G
    wrote on last edited by
    #1

    Hello, I've been working lately on my application and noticed that NAM is sending two requests for some reason.

    I'm getting a full reply with the data I want and an empty reply. I checked the code out a few times but couldn't figure out why it would do two requests.

    Manager class isn't really a wrapper around NAM, but a manager for the resource I'm managing.

    Manager::Manager( QNetworkAccessManager* nam)  :
        nam(nam)
    {
    
        qDebug() << nam->objectName();
    
    
        auto *test = new Fetcher(nam, QUrl("http://sometestsite.ninja"));
        Fetcher *test2 = new Fetcher(nam, QUrl("http://bing.com"));
        //auto *test3 = new Fetcher(nam, QUrl("http://google.com"));
    
        //test->deleteLater();
    }
    

    and

    Fetcher::Fetcher( QNetworkAccessManager* nam,
                      QUrl url)
        :
         nam(nam)
    {
    
        connect(nam,SIGNAL(finished(QNetworkReply*)),
                this, SLOT(finishedRequest(QNetworkReply*)));
    
        QNetworkRequest request;
        request.setOriginatingObject(this);
        request.setUrl(url);
        request.setRawHeader("User-Agent","Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36");
        nam->get(request);
    
    }
    
    void Fetcher::finishedRequest(QNetworkReply *reply) {
    
    
    
        qDebug() << reply->request().url();
        qDebug() << reply->readAll();
        qDebug() << reply->request().originatingObject();
        reply->deleteLater();
    }
    

    Example output:

    QUrl("http://bing.com")
    data here
    Fetcher(0xabd380)
    QUrl("http://bing.com")
    ""
    Fetcher(0xabd380)
    

    Any ideas on how to stop it? Only thing that worries me is it being affected in production. I tried using a condition (if buffersize <= 0) then return) but failed as it stopped receiving the reply. My apologies in advance, I'm still learning my way around C++/Qt5 in general.

    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