Linux下QT中执行shell命令

当须要在QT中执行shell命令时能够利用如下方法:shell

(1)首先包含头文件:函数

#include <QProcess>spa

(2)执行shell命令:orm

QProcess::execute("ls");进程

/////////////////////ip

#include  <QProcess>get

void Widget:on_pushButton_clicked()string

{it

//*cli

 system("ls");//调用LINUX C函数库中的system(const char *string);

*//

#######@@@@@

QProcess ::execute("ls");//调用QT里的函数

@@@@@############

----------------------

QProcess *proc = new QProcess;

proc->start("ls");

---------------------------

Tip:以上三种方法均可以,但前两种方法会阻塞进程,知道ls程序结束,

而第三种则不会阻塞进程,能够多任务运行。

相关文章
相关标签/搜索