I'm new in a QT development. I'm trying to do a simple Post Request to a rest service in order to read a Json Data.
Currently I've wrote:
void LoginWindow::on_pushButton_clicked(){
// Setup the webservice url
QUrl serviceUrl = QUrl("http://urlrestservice.com");
QByteArray postData;
postData.append("request=userdata&");
postData.append("user=myusername&");
postData.append("password=mypasswod");
// Call the webservice
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
//QNetworkRequest::setHeader();
QNetworkRequest request(serviceUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(
QString("text/xml")));
connect(manager, SIGNAL(finished(QNetworkReply*)), this,
SLOT(serviceRequestFinished(QNetworkReply*)));
manager->post(request, postData);
}
After that I don't know how procede. I've made a empty method
void LoginWindow::serviceRequestFinished(QNetworkReply* reply){ }
but I dont know how do inside of them.
The Post request should return me:
{
"response": {
"status": "200",
"message": "Correct request"
},
"data": [
[
{
"href": "link",
"text": "string matr"
},
{
"href": "link",
"text": "string type"
},
{
"href": "link",
"text": "string name"
},
{
"href": "link",
"text": "string state"
}
]
]
}
I've read that exist a library QJson but I think the official doc is a little bit confused and I can not figure out how to proceed.