当需要在QT中执行shell命令时可以利用以下方法:

(1)首先包含头文件:

#include <QProcess>

(2)执行shell命令:

QProcess::execute("ls");
/
#include  <QProcess>
void Widget:on_pushButton_clicked()
{
//*
 system("ls");//调用Linux C函数库中的system(const char *string);
*//
#######@@@@@
QProcess ::execute("ls");//调用QT里的函数
@@@@@############
----------------------
QProcess *proc = new QProcess;
proc->start("ls");
---------------------------

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

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