这是我的方法,但不起作用。
void ApplicationUI::Post(const QString &id,const QString &name,const QString &surname,const QString &grade, const QString &dob,const QString &language,const QString &school, const QString &gender,const QString &cellno,const QString ®istrationDate)
{
this->connection = new QNetworkAccessManager(this);
connect(this->connection, SIGNAL(finished(QNetworkReply*)), this, SLOT(postFinished()));
QUrl url("http://172.27.15.7/BB10_Scripts/Registration.php");
QUrl postParams;
postParams.addQueryItem("id",id);
postParams.addQueryItem("name", name);
postParams.addQueryItem("surname",surname);
postParams.addQueryItem("grade",grade);
postParams.addQueryItem("dob",dob);
postParams.addQueryItem("language",language);
postParams.addQueryItem("school",school);
postParams.addQueryItem("gender",gender);
postParams.addQueryItem("cellno",cellno);
postParams.addQueryItem("registrationDate",registrationDate);
QByteArray data;
data.append(postParams.data);
data.remove(0,1);
QNetworkRequest req;
req.setUrl(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
this->connection->post(req,postParams.encodedQuery());());
bool ok = QObject::connect(connection, SIGNAL(finished(QNetworkReply*)), this, SLOT(postFinished()));
Q_ASSERT(ok);
Q_UNUSED(ok);
qDebug() << "Connection is success : ? : " << ok;
}
我收到消息
连接成功:? :是的 过程476930267(CascadesProject)终止SIGSEGV代码= 1 fltno = 11&gt; ip = 79f70ce2&gt;(/ base/usr/lib/qt4/lib/libQtNetwork.so.4.8.5@_ZNK13QNetworkReply5errorEv+0x9)> mapaddr = 00060ce2。 ref = 00000004 bdslot = 1
答案 0 :(得分:-1)
postParams.addQueryItem("id", id);
postParams.addQueryItem("name", name);
postParams.addQueryItem("surname", surname);
postParams.addQueryItem("grade", grade);
postParams.addQueryItem("dob", dob);
postParams.addQueryItem("language", language);
postParams.addQueryItem("school", school);
postParams.addQueryItem("gender", gender);
postParams.addQueryItem("cellno", cellno);
postParams.addQueryItem("registrationDate",registrationDate);
QNetworkRequest request;
request.setUrl(QUrl("http://172.27.15.7/BB10_Scripts/Registration.php?"));
bool res;
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
Q_UNUSED(res);
this->reply = connection->post(request, postParams.encodedQuery());
res = QObject::connect(this->reply, SIGNAL(finished()),this, SLOT(postFinished()));
Q_ASSERT(res);
Q_UNUSED(res);
qDebug() << "Connection is success : ? : " << res;