1

I need to compose a string like:

<page myIndex = "1">

where 1 is the value of a variable stored in memory.

My fist try:

QString str = "<page pageIndex = " + myVar + ">";

But it does not contain the ' " ' around the myVar value. I've tried with ' only, like this:

QString str = "<page pageIndex = " + '"' + myVar + '"' + ">";

but it gives compile error.

Ale
  • 285
  • 2
  • 7
  • 18

1 Answers1

3

There are already several answers for your problem but I'd like to add one more to the list:

auto str = QString("<page pageIndex = \"%1\">").arg(myVar);

Seems to be a bit more elegant from my point of view and gets the job done.

Dusteh
  • 1,496
  • 16
  • 21