Skip to content

Instantly share code, notes, and snippets.

@CypherpunkSamurai
Forked from rla/code.cpp
Created October 27, 2021 12:54
Show Gist options
  • Save CypherpunkSamurai/441c1276f6f9a8dbd6d9f2ce07e928f1 to your computer and use it in GitHub Desktop.
Save CypherpunkSamurai/441c1276f6f9a8dbd6d9f2ce07e928f1 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment