标签:
使用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->addArgument("qmake");
proc->addArgument("-o");
proc->addArgument("/home/sjq/work/jobs/test6/test/Makefile");
proc->addArgument("/home/sjq/work/jobs/test6/test/cmd.pro");
if(proc->start())
{
cout<<"error"<<endl;
}
其中使用方法就在于对QProcess 的调用如
mkdir TEST
QProcess *proc = new QProcess;
proc->addArgument("mkdir");
proc->addArgument("TEST");
if(proc->start())
{
cout<<"error"<<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
标签:
原文地址:http://www.cnblogs.com/findumars/p/5782446.html