can anybody explain why QStringList() used in below line ?
Solved
General and Desktop
-
i want to understand below statement
qProcessSysCmd ->start("bash",QStringList() << "-c" << sCommand.toLatin1().data());
what this statement do internally ?
-
Apparently,
start()
requires aQStringList
. Instead of creating it earlier, like so:QStringList args; args.append("-c"); args.append(sCommand);
the author has decided to create it in-place (good idea, btw, it allows the compiler to optimize it). The syntax is rather old, in post C++11 world we'd rather write it like this:
qProcessSysCmd ->start("bash", { "-c", sCommand });
EDIT Removed
.toLatin1().data()
as it is, indeed, a bad idea to do this. -
@sierdzio said in can anybody explain why QStringList() used in below line ?:
sCommand.toLatin1().data()
btw: this is useless and even wrong when the command contains non-latin1 characters