How to get INT variable to QProcess write command?

Viewed 65

Following code works

QProcess *p = new QProcess();
p->write("10 cats\n");

Now I need to send int variable to write command.

Something like:

QProcess *p = new QProcess();
int i = 10;
p->write(i << " cats\n");
1 Answers

Looks like you want to append variables to then pass them as parameter.

try something like this

int i{10};
QString formattedString{QString("%1 cats\n").arg(i)};
QProcess* p = new QProcess();
p->write(formattedString.toStdString().c_str());
Related