【问题标题】:i have made changes to the code我已经对代码进行了更改
【发布时间】:2015-03-05 10:28:42
【问题描述】:

这是我的方法,它不起作用。

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 &registrationDate)
{
    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 >ip=79f70ce2 >(/base/usr/lib/qt4/lib/libQtNetwork.so.4.8.5@_ZNK13QNetworkReply5errorEv+0x9) >mapaddr=00060ce2。 ref=00000004 bdslot=1

【问题讨论】:

  • 有很多名为"id"的参数。此外,您发送请求两次。此外,您为每次调用 Post 方法创建一个新的 QNetworkAccessManager。另外,您将postParams 放入data,但不要发送data,而是postParams.encodedQuery();决定一个。
  • 这就是我现在所拥有的。但同样的消息仍然存在
  • 我已经对上面的代码进行了更改,但它仍然是一样的。请指教
  • 你还没有解决所有@leemes 点,所以难怪它不起作用。

标签: c++ qt


【解决方案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;

【讨论】:

  • 感谢您的积极投入。我终于破解了
猜你喜欢
  • 2015-05-06
  • 2023-01-19
  • 1970-01-01
  • 2013-06-23
  • 1970-01-01
  • 1970-01-01
  • 2014-08-13
  • 1970-01-01
  • 2017-09-16
相关资源
最近更新 更多