No, of course not. You schedule as many requests as you want and QNetworkAccessManager will execute them when the right time comes. As far as I remember it will be sending four requests at a time.
No, but having the loop is ok as well. Scheduling 1000 requests should take just a couple of milliseconds.I need a loop for sending multiple request,right?!
I am new to qt. I am not able to find any good resource in multithreading. I just want to do fuzzing on web applictions which i was assigned to do testing.
Here is exactly what i wanted:
I need to send more than 1000 or 10,000 requests to a web application without affecting the GUI(i tried to run 10,000 request in main thread, it's affecting the gui, not able to access any other items). so i wanted to run the QNAM &loop in a separate thread or any other way in such a way that it should not affect the other tasks. Can you give me a sample snippet or tutorial links to achieve this
Thank you
One way to do it is to have a worker object and move it to a QThread
Qt Code:
Worker *worker = new Worker(); // class derived from QObject worker->moveToThread(thread); connect(thread, SIGNAL(started()), worker, SLOT(start())); // Worker needs a slot that start the work thread->start();To copy to clipboard, switch view to plain text mode
Cheers,
_
qthread (3rd August 2014)
Thanks it worked for me![]()
How can i distinguish the responses?! I'm sending 1000 requests.
I can use response->request().url() function to get the corresponding url. However i want to set a unique number for each request and display along with corresponding response. How to do that in QNAM?
One option would be to have a mapping from the QNetworkReply pointer to your reference data, e.g. using QHash.
In your case where you only need a single number, it is probably quicker to just set this value as a dynamic property on the QNetworkReply object.
See QObject::setProperty().
Cheers,
_
Just remember that QNetworkReply is a QIODevice which in turn is a QObject thus accessing it from more than one thread is not safe. Push the object to the main thread before you try accessing it. The original thread will probably not try accessing the object after finished() is emitted but it is better to be safe than sorry.
Which of course doesn't negate the fact that there is probably no point in using any extra threads here..
I will be thankful if anyone give me a sample snippet to distinguish each QNAM response from others![]()
Each request is handled by a QNetworkReply object. So each request has a different, distinguishable, pointer to a QNetworkReply instance.
Each instance has the QNetworkRequest that it was created for.
Qt Code:
void MyClass::networkRequestFinished(QNetworkReply *reply) { qDebug() << "Request for" << reply->request().url() << "finished" << (reply->error() != QNetworkReply::NoError ? "with an error" : "without error"); }To copy to clipboard, switch view to plain text mode
Cheers,
_
Thanksis it possible to pass a unique value to QNAM and access them via QNetworkReply other than URL ?!
QNetworkReply is a QObject derived class, you can set any value as a dynamic property.
See QObject::setProperty.
Cheers,
_
Bookmarks