In Qt 4, the following code using QUrl works:
QUrl u;
foreach (const settings::PostItem & pi, settings.post)
u.addQueryItem(pi.name, pi.value);
postData = u.encodedQuery();
NOTES: this code is from wkhtmltopdf and postData is a QByteArray.
However, Qt 5 does not have the addQueryItem() function anymore. How do you port this code?
In order to ensure compatibility with
Qt4, add the following lines at the top of your file:This means that
QUrlQuerywill only be#included if you are compiling againstQt5.0.0 or greater.Then add the following line above the code specified in the question:
and then insert this code below the code specified in the question:
NOTE:
toUtf8()is used becausepostDatais aQByteArrayandquery()returns aQString.toAscii()was deprecated inQt5, but UTF-8 is a subset of ASCII with Unicode characters only when necessary.EDIT: In the case you want to use a real
QUrlthat has a URL portion, add this: