Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a system command in Qt?

Tags:

file

system

qt

qt4

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!?

like image 752
defiant Avatar asked Jul 12 '10 10:07

defiant


People also ask

How do I run a command in Qt?

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

How do I run a Linux command in Qt?

@grullo said in Run command line from Qt app in linux: QString cmdline = ". /home/grullo/xmip-bundle/build/xmipp. bashrc"; I guess the initial dot (".") is making your command line relative, so that path is not found when set the working directory.

Where is Qt command prompt?

The "Qt command prompt" is nothing but the standard Windows command prompt (aka "CMD.exe"), but with the PATH environment variable prepended by the Qt "bin" path. This means you can just enter any Qt program without a full path, because the command prompt will find it via PATH.


2 Answers

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.

like image 118
mosg Avatar answered Sep 19 '22 02:09

mosg


QProcess::execute() may be helpful:

QProcess::execute("gedit /home/oDx/Documents/a.txt")); 
like image 26
baziorek Avatar answered Sep 17 '22 02:09

baziorek