66

I have to run a system command in Qt, but I have to give an argument for that command.

for example opening a text file with gedit:

gedit /home/oDx/Documents/a.txt"

but the path /home/oDx/Documents/a.txt will be in a variable like docPath.

How can I achieve this?

defiant
  • 3,161
  • 11
  • 41
  • 65

3 Answers3

93
QProcess process;
process.start("gedit", QStringList() << docPath);

the same as above

QProcess process;
process.start("gedit", QStringList() << "/home/oDx/Documents/a.txt");

Also, read this.

Community
  • 1
  • 1
mosg
  • 12,041
  • 12
  • 65
  • 87
17

QProcess::execute() may be helpful, although is deprecated:

QProcess::execute("gedit /home/oDx/Documents/a.txt");
cbjeukendrup
  • 3,216
  • 2
  • 12
  • 28
baziorek
  • 2,502
  • 2
  • 29
  • 43
2

As of Qt 6.0, you can use QProcess::startCommand:

QProcess process;
process.startCommand("gedit /home/oDx/Documents/a.txt");