2

Is it possible to use QUrlQuery to append data without striping the url?

Using the code bellow will strip everything after the "?" and the result is:

https://foobar.com/Info.xml.aspx?userdata=1234

I would like to get:

https://foobar.com/Info.xml.aspx?user=jack&userdata=1234

QUrl url("https://foobar.com/Info.xml.aspx?user=jack&");
QString data = "1234"; 

QUrlQuery query;
query.addQueryItem("userdata", data);
url.setQuery(query); 

I'm asking because i need to make multiple calls, every time adding a new parameter and "building" the url from scratch every time is annoying.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Jack
  • 77
  • 2
  • 12

1 Answers1

4

You have to get the query and then add the item:

QUrl url("https://foobar.com/Info.xml.aspx?user=jack&");

QString data = "1234";
QUrlQuery query(url.query());
query.addQueryItem("userdata", data);
url.setQuery(query);

qDebug()<<url;

Output:

QUrl("https://foobar.com/Info.xml.aspx?user=jack&userdata=1234")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241