I want to send a post request to a server and I do something like this:
function makePost(){
QNetworkAccessManager *networkManager = new QNetworkAccessManager();
qDebug()<<"1";
bool ret = connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
qDebug()<<"2: " <<ret;
QUrl serviceUrl = QUrl("http://someurl/json");
QNetworkRequest request(serviceUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QString content = "";
networkManager->post(request, content.toUtf8());
}
But the slot serviceRequestFinished()
is not called at all! I must mention that I used Wireshark to track the request/response and I found that the request(post) is being sent and the server returns a response back with status 200
(ok). Also the ret
variable returns true
, i.e. the connection between signal and slot was made successfully. Any of you have any idea why this doesn't work? Thank you!:)
EDIT
The code that cause the problem - see my answer - is this:
{
MyObjectWithSlot obj;
obj.makePost();
}