使用QProcess QThread

============================================

#include <QProcess>
int main()
{
QProcess::execute("ls");
return 0;
}

============================================

 

QProcess *poc = new QProcess; 
poc-> start( "ping 222.207.53.1> hh "); 
打开hh文档 读取里面的内容给QTextEdit

============================================

QProcess *proc = new QProcess;
proc-&gt;addArgument("qmake");
proc-&gt;addArgument("-o");
proc-&gt;addArgument("/home/sjq/work/jobs/test6/test/Makefile");
proc-&gt;addArgument("/home/sjq/work/jobs/test6/test/cmd.pro");
if(proc-&gt;start())
{
cout&lt;&lt;"error"&lt;&lt;endl;
}

其中使用方法就在于对QProcess 的调用如

mkdir TEST

QProcess *proc = new QProcess;
proc-&gt;addArgument("mkdir");
proc-&gt;addArgument("TEST");

if(proc-&gt;start())
{
cout&lt;&lt;"error"&lt;&lt;endl;
}

============================================

另外的一种使用方法,一种交换

while ( proc-> isRunning()) 

stringOut = proc-> readLineStdout(); 
textEdit-> append( stringOut ); 

这样能读出来,但是不知道怎么停下来,在读的proc执行的过程中,窗口被冻结 
最后用了qApp-> processEvents()来解决的 
我再去研究研究pthread.

============================================

下面是使用Qthread的一种方法

===============================================

#include <QProcess>
#include <QThread>
class MyThread : public QThread
{
public:
void run();
};

void MyThread::run()
{
QProcess::execute("service lighttpd restart");
}

int main()
{
MyThread *thread=new MyThread;
thread->start();
}

============================================

#include <QProcess>
#include <QThread>
#include <QString>
#include <QStringList>
class MyThread : public QThread
{
public:
void run();
};

void MyThread::run()
{
QProcess *testc=new QProcess;
QString program = "rm";
QStringList arguments;
arguments << "./a.txt";
testc->start(program, arguments);
}

int main()
{
MyThread *thread=new MyThread;
thread->start();
}

细化操作--不打印显示任何的操作结

http://blog.csdn.net/taiyang1987912/article/details/46293929

04-13 18:34