Using Qprocess Qthread
============================================
#include <QProcess>
int main ()
{
Qprocess::execute ("LS");
return 0;
}
============================================
Qprocess *poc = new Qprocess;
poc-> Start ("Ping 222.207.53.1> hh");
Open the HH document to read the contents to 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;
}
The use of this method lies in the invocation of qprocess as
mkdir TEST
Qprocess *proc = new Qprocess;
Proc->addargument ("mkdir");
Proc->addargument ("TEST");
if (Proc->start ())
{
cout<< " Error "<<endl;
}
============================================
Another method of use, an exchange
while (proc-> isrunning ())
{
Stringout = proc-> readlinestdout ();
Textedit-> append (stringout);
}
This can be read out, but do not know how to stop, in the process of reading proc execution, the window is frozen
Finally, the qapp-> processevents () was used to solve the
I'll study pthread again.
============================================
Here's a way to use 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 ();
}
Fine-grained operation--do not print to show any operation knot
At the time of the summary refer to some practices of the net:)
http://no001.blog.51cto.com/1142339/450327
Several methods of implementing Linux shell calls under QT