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