How to run a system command in Qt?

QtFileQt4System

Qt Problem Overview


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

for example opening gedit with a text file. like "gedit /home/oDx/Documents/a.txt"

but the path "/home/oDx/Documents/a.txt" will be in a variable like "docPath". so how can i do it!?

Qt Solutions


Solution 1 - Qt

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.

Solution 2 - Qt

QProcess::execute() may be helpful:

QProcess::execute("gedit /home/oDx/Documents/a.txt"));

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondefiantView Question on Stackoverflow
Solution 1 - QtmosgView Answer on Stackoverflow
Solution 2 - QtbaziorekView Answer on Stackoverflow