RegMe
25th May 2016, 11:33
Hi Forum,
I have a problem, I want to get the response from the serveur if the operation is Ok or not, So I analysed
QNetworkRequest::HttpStatusCodeAttribute
// *** createProject( param ) ***
//Create project using post json
// ...
reply = manager->post(request, dataByteArray);
/* The finished() signal is triggered once an HTTP request is complete, by connect method we are connecting finished signal with the slot method onRequestFinished(user defined method). If it returns true it means connection is successful else not. You can process the response of the call in this user defined method */
result = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
// *** slot onFinished() ***
bool Connection::onFinished()
{
codeResponse = false;
qDebug() << "QNetworkRequest::HttpStatusCodeAttribute" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute ).toInt() << "received";
if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 201)
{
codeResponse = true;
}
return codeResponse;
}
// *** getter ***
bool Connection::getResponse()
{
return codeResponse;
}
QML code
connection.createProject( param );
rep = connection.getResponse()
console.log("Response: "+rep)
infoAdd.open()
All is OK, but in QML sometimes function getResponse() runs before the slot onFinished() ??
So there is an other way whitout using getResponse() to get response from onFinichid() ?
I tried to use connection.onFinichid() in QML but it executed 2 times :
1st with connection.createProject( param ), 2nd directly connection.onFinichid() == > Response always = false
I try to find an easy way to get the resp without getter getResponse()
Cheers,
I have a problem, I want to get the response from the serveur if the operation is Ok or not, So I analysed
QNetworkRequest::HttpStatusCodeAttribute
// *** createProject( param ) ***
//Create project using post json
// ...
reply = manager->post(request, dataByteArray);
/* The finished() signal is triggered once an HTTP request is complete, by connect method we are connecting finished signal with the slot method onRequestFinished(user defined method). If it returns true it means connection is successful else not. You can process the response of the call in this user defined method */
result = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
// *** slot onFinished() ***
bool Connection::onFinished()
{
codeResponse = false;
qDebug() << "QNetworkRequest::HttpStatusCodeAttribute" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute ).toInt() << "received";
if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 201)
{
codeResponse = true;
}
return codeResponse;
}
// *** getter ***
bool Connection::getResponse()
{
return codeResponse;
}
QML code
connection.createProject( param );
rep = connection.getResponse()
console.log("Response: "+rep)
infoAdd.open()
All is OK, but in QML sometimes function getResponse() runs before the slot onFinished() ??
So there is an other way whitout using getResponse() to get response from onFinichid() ?
I tried to use connection.onFinichid() in QML but it executed 2 times :
1st with connection.createProject( param ), 2nd directly connection.onFinichid() == > Response always = false
I try to find an easy way to get the resp without getter getResponse()
Cheers,