sattu
8th January 2014, 14:50
Hi Everyone, I have a simple requirement on my Arm-Linux embedded platform wherein I need to post to a URL and wait for the reply. I achieve that using the following code-
void MyApp::MyApp()
{
m_networkManager = new QNetworkAccessManager(this); // Instance variable
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(onRequestCompleted(QNetworkReply *)));
}
void MyApp::getData()
{
QByteArray dataToBePosted;
QNetworkRequest request;
request.setUrl(QUrl("http://www.domain.foo"));
m_networkManager->post(request,dataToBePosted);
}
void MyApp::onRequestCompleted(QNetworkReply *reply)
{
QByteArray data = reply->readAll();
reply->deleteLater();
}
I have 2 doubts regarding usage of QNetworkAccessManager class-
1) What I observed is that if I post to a valid URL I immediately get a response, but if the URL is invalid then it takes some time for the reply to come (sometimes like 40 secs).
Moreover, if the URL is invalid then I observe an increase in memory usage in my application after the following line-
m_networkManager->post(request,dataToBePosted);
I know this sounds very strange but this is what is happening. If the URL exists then everything is fine, but by mistake if I post to an invalid URL then my memory usage immediately shoots up :confused:
2) In Qt Documentation it is mentioned that
One QNetworkAccessManager should be enough for the whole Qt application.
Suppose I use 2 QNetworkAccessManager objects in my application, will that create any issue?
I would be really glad if someone would clarify my doubts.
void MyApp::MyApp()
{
m_networkManager = new QNetworkAccessManager(this); // Instance variable
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(onRequestCompleted(QNetworkReply *)));
}
void MyApp::getData()
{
QByteArray dataToBePosted;
QNetworkRequest request;
request.setUrl(QUrl("http://www.domain.foo"));
m_networkManager->post(request,dataToBePosted);
}
void MyApp::onRequestCompleted(QNetworkReply *reply)
{
QByteArray data = reply->readAll();
reply->deleteLater();
}
I have 2 doubts regarding usage of QNetworkAccessManager class-
1) What I observed is that if I post to a valid URL I immediately get a response, but if the URL is invalid then it takes some time for the reply to come (sometimes like 40 secs).
Moreover, if the URL is invalid then I observe an increase in memory usage in my application after the following line-
m_networkManager->post(request,dataToBePosted);
I know this sounds very strange but this is what is happening. If the URL exists then everything is fine, but by mistake if I post to an invalid URL then my memory usage immediately shoots up :confused:
2) In Qt Documentation it is mentioned that
One QNetworkAccessManager should be enough for the whole Qt application.
Suppose I use 2 QNetworkAccessManager objects in my application, will that create any issue?
I would be really glad if someone would clarify my doubts.