This code is working for me but i don't want to use the "connect" here. I want the reply in the same function.
Why ? What's wrong with the connect() ?
Anyway, to answer your question, you will have to block the processing somehow. It's not tested, but maybe you can
1) busy waiting with processEvents calls:
void HttpPost::on_pushButton_clicked()
{
params.addQueryItem("testSample","indu");
postData = params.encodedQuery();
manager->setCookieJar(new QNetworkCookieJar(manager));
QNetworkReply * reply = manager->post(req, postData);
while( ! reply->isFinished() ){
qApp->processEvents();
}
// reply should be finished by now
}
void HttpPost::on_pushButton_clicked()
{
params.addQueryItem("testSample","indu");
postData = params.encodedQuery();
manager->setCookieJar(new QNetworkCookieJar(manager));
QNetworkReply * reply = manager->post(req, postData);
while( ! reply->isFinished() ){
qApp->processEvents();
}
// reply should be finished by now
}
To copy to clipboard, switch view to plain text mode
2) use QDialog (or QProgressDialog)
void HttpPost::on_pushButton_clicked()
{
params.addQueryItem("testSample","indu");
postData = params.encodedQuery();
manager->setCookieJar(new QNetworkCookieJar(manager));
QDialog dialog; dialog.
setWindowTitle("Waiting...");
// ... prepare the dialog layout somehow
connect (manager, SIGNAL(finished(QNetworkReply *)), &dialog, SLOT(accept()));
QNetworkReply * reply = manager->post(req, postData);
dialog.exec();
// reply should be finished by now, but not if you close the dialog manually
}
void HttpPost::on_pushButton_clicked()
{
params.addQueryItem("testSample","indu");
postData = params.encodedQuery();
manager->setCookieJar(new QNetworkCookieJar(manager));
QDialog dialog; dialog.setWindowTitle("Waiting...");
// ... prepare the dialog layout somehow
connect (manager, SIGNAL(finished(QNetworkReply *)), &dialog, SLOT(accept()));
QNetworkReply * reply = manager->post(req, postData);
dialog.exec();
// reply should be finished by now, but not if you close the dialog manually
}
To copy to clipboard, switch view to plain text mode
Again, this code is not tested.
Bookmarks