#includeint main() { QUrl url("http://example.com"); url.addEncodedQueryItem("key1", "value1"); url.addEncodedQueryItem("key2", "value2"); // output: http://example.com/?key1=value1&key2=value2 qDebug() << url.toString(); return 0; }
#includeIn this example, the QUrlQuery object is used to build a query string with two query parameters, key1 and key2, both with corresponding values. The addQueryItem() function is called twice to add these items to the query. The resulting query string is then set as the URL's query using the setQuery() function. The resulting URL is printed to the console using the toString() function. Both examples demonstrate how QUrl addEncodedQueryItem() can be used to add query parameters to URLs. The Qt library provides many other functions for manipulating URLs, making it a powerful tool for web development.int main() { QUrl url("http://example.com"); QUrlQuery query; query.addQueryItem("key1", "value1"); query.addQueryItem("key2", "value2"); url.setQuery(query); // output: http://example.com/?key1=value1&key2=value2 qDebug() << url.toString(); return 0; }