Here's an example. I can fill in the form 100 times, and download 100 different websites, while using the same QNetworkAccessManager.
@
class ProgramCore : public QObject
{
private:
Q_OBJECT
MainWindow *gui;
QNetworkAccessManager *manager;
private slots:
void getPage() const
{
QNetworkRequest req;
req.setUrl(QUrl("My url"));
QByteArray postData = gui->readFormData();
// Connect the signal from the reply, not from the manager.
// The QNetworkReply will download data in the background. Your GUI is free
// during this time.
QNetworkReply *reply = manager->post(req, postData);
connect(reply, SIGNAL(finished()), this, SLOT(processReply()));
}
void processReply() const
{
// Use QObject::sender() to find the object that emitted the signal
QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());
QString answer = QString::fromUtf8(reply->readAll());
qDebug () << answer;
// Make sure you don't have a memory leak! Delete the object when you've finished
reply->deleteLater();
}
public:
ProgramCore(QObject *parent = 0) : QObject(parent)
{
this->gui = new MainWindow(this);
this->manager = new QNetworkAccessManager(this);
connect(gui, SIGNAL(userSubmittedTheForm()), this, SLOT(getPage()));
}
}
@
Final notes: This is just Repetition, not "Indirect Recursion". You only wanted to repeat a task, so you shouldn't use threads to do that. Threads are for Parallel Processing -- for example, making 2 CPU cores process different data at the same time.