I see your point now, thanks. Indeed, _http member variable lives in the main thread when I call a.start(). Run method of the "a" instance uses _http once and then exits with "exec()", leaving event loop alive.
I will rearrange the code by the scheme below. Do you consider it to be a proper usage of event loop and QNAM?
{
public:
myClass ()
{
connect(this, SIGNAL(doComm()), this, SLOT(onDoComm()), Qt::Queued);
}
void run() { exec(); }
void startComm() {emit doComm();}
signals:
void doComm();
slots:
void onDoComm() {_http.post(...);};
void isFinished(QNetworReply* r) {r->deleteLater(); emit doComm();}
private:
QNAM _http;
};
main
{
myClass a;
a.start();
a.startComm();
int i;
std::cin >> i;
}
class myClass : public QThread
{
public:
myClass ()
{
connect(this, SIGNAL(doComm()), this, SLOT(onDoComm()), Qt::Queued);
}
void run() { exec(); }
void startComm() {emit doComm();}
signals:
void doComm();
slots:
void onDoComm() {_http.post(...);};
void isFinished(QNetworReply* r) {r->deleteLater(); emit doComm();}
private:
QNAM _http;
};
main
{
myClass a;
a.start();
a.startComm();
int i;
std::cin >> i;
}
To copy to clipboard, switch view to plain text mode
Bookmarks