Skip to content

Instantly share code, notes, and snippets.

@rla
Created July 23, 2012 13:12
Show Gist options
  • Save rla/3163550 to your computer and use it in GitHub Desktop.
Save rla/3163550 to your computer and use it in GitHub Desktop.
Sending JSON POST request with Qt
void SyncService::sync()
{
QUrl url(SYNC_URL);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(syncRequestFinished(QNetworkReply*)));
QByteArray data = QtJson::Json::serialize(collectSyncData());
// FIXME for debug
qDebug() << "Sync" << QString::fromUtf8(data.data(), data.size());
manager->post(request, data);
}
@imdanielsp
Copy link

Thanks a lot! I am pretty new to Qt and haven't learned the API yet.

@muchirajunior
Copy link

thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment