How to run a system command in Qt?

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

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

回答1:

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.



回答2:

QProcess::execute() may be helpful:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!