qt - QNetworkAccessManager returning empty results -
i struggling qnetworkaccessmanager quite sometime. googled lot, donot find solution this.
i creating client using qaccessmanager talk rest server. qnetworkreply not returning results. server working client not returning results. on top of server gets called 3 times , server crashing. hope 1 can figure out going wrong. attaching client code.
i tried different approches connecting finished signal of networkaccessmanager, qnetworkreply e.t.c. of them ends in giving same error "connection closed" or readall bytearray being empty.
void restclientcore::connecttoserver() { m_networkmanager = new qnetworkaccessmanager(this); qurl url("http://localhost"); url.setport(5432); qbytearray postdata; postdata.append("/?userid=user"); postdata.append("&site=site"); qnetworkreply *reply = m_networkmanager->post(request,postdata); connect(reply, signal(readyread()),this, slot(slotreadyread())); connect(reply, signal(finished()), this, slot(onrequestcompleted())); } void restclientcore::onrequestcompleted() { qnetworkreply *reply = qobject_cast<qnetworkreply *>(sender()); if(reply->error()) { qdebug() <<reply->bytesavailable() << reply->errorstring(); } else { qdebug() << reply->readall(); } reply->deletelater(); } void restclientcore::slotreadyread() { qnetworkreply *reply = qobject_cast<qnetworkreply *>(sender()); qdebug() << reply->readall(); }
thanks in advance regards rejo
Comments
Post a Comment