Setting http get request parameters using Qt Setting http get request parameters using Qt curl curl

Setting http get request parameters using Qt


Unfortunately, QUrl::addQueryItem() is deprecated in qt5 but starting from there I found the QUrlQuery class which has an addQueryItem() method and can produce a query string that is acceptable for QUrl's setQuery() method so it now looks like this and works fine:

QUrl url("https://api.parse.com/1/login");QUrlQuery query;query.addQueryItem("username", "test");query.addQueryItem("password", "test");url.setQuery(query.query());QNetworkRequest request(url);request.setRawHeader("X-Parse-Application-Id", "myappid");request.setRawHeader("X-Parse-REST-API-Key", "myapikey");nam->get(request);

Thanks for the tip Chris.


I believe QUrl::addQueryItem() is what you're looking for

QUrl url("https://api.parse.com/1/login");url.addQueryItem("username", "test");url.addQueryItem("password", "test");...


Try to use QtCUrl. It's easy, if you are familiar with curl.

QtCUrl cUrl;QUrl url("https://api.parse.com/1/login");url.addEncodedQueryItem("username", "test");url.addEncodedQueryItem("password", "test");QtCUrl::Options opt;opt[CURLOPT_URL] = url;QStringList headers;headers    << "X-Parse-Application-Id: myappid"    << "X-Parse-REST-API-Key: myapikey"opt[CURLOPT_HTTPHEADER] = headers;QString result = cUrl.exec(opt);