QNetworkaccessmanager - post
-
Hello
When i try to figure out how to use this QNAM and post I Tried this.I will fill the bytearray with some id (Numeric) and make it as a list.
It works with one value but not with 2 or more and I recive an Unkown error in all of my cases.
Where is the missing part.
The contact to the url-- is all right
I fill up the bytearray in a loop
@ QByteArray postData;for (int i = 0; i < selectedToAck.size(); ++i) {postData.append("m_iFuelSensor=");
postData.append(model->item(index.row(),0)->data(Qt::DisplayRole).toString());@@/*
-
connection();
-
param postdata- bytearray
-
try to do a form post with QNetworkAccessmanager
*/
void Logs::connection( QByteArray postData)
{manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(finishedSlot(QNetworkReply*)));QUrl url(globalP->getGCUUrl() + "/fuelParams.htm? ");
reply = manager->post(QNetworkRequest(url),postData);
}
/*
-
finishedSlot();
-
param replay- QNetworkReply
-
answer of the post metchod
/
void Logs::finishedSlot(QNetworkReply reply)
{QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute );
QMessageBox msgBox;
QVariant tempQ = QVariant(statusCodeV.toString());
msgBox.setText(tempQ.toString() + " " + reply->errorString());
int ret = msgBox.exec();// "200 OK" received?
if (statusCodeV.toInt()==200)
{msgBox.setText("Successfull!..."); int ret = msgBox.exec(); QByteArray bytes = reply->readAll(); // bytes const QString string(bytes); // string QMessageBox msgBox; msgBox.setText(string ); msgBox.exec();}
else
{
msgBox.setText("UnSuccessfull!...");
int ret = msgBox.exec();
}selectedToAck.clear();
setActiveAlarms();delete reply;
delete manager;
}
@ -
-
I even got this in the debugwindow
bq. X Error: BadWindow (invalid Window parameter) 3
Major opcode: 15 (X_QueryTree)
Resource id: 0x165b0ef
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 40 (X_TranslateCoords)
Resource id: 0x165b0ef
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 15 (X_QueryTree)
Resource id: 0x165c579
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 40 (X_TranslateCoords)
Resource id: 0x165c579
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 15 (X_QueryTree)
Resource id: 0x165e494
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 40 (X_TranslateCoords)
Resource id: 0x165e494 -
More errors
I got the errorcode 302 unknown error when i do my post but it changes the value in the textbox.
if I send one value.
When i changed to get operation I got the errorcode 200 "OK"
If someone have a simple example to show or some great hints to get me go on with this "Problem"
I would be very happy. -
-
[quote author="toho71" date="1324560334"
Maybe I have to use Qhttp instead
[/quote]You will run into the very same problems with constructing the URL and/or preparing the post data. You will need to understand HTTP protocol basics before using it in a class.
-