Several methods of implementing Linux shell calls under QT

Source: Internet
Author: User

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-&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;
}

The use of this method lies in the invocation of qprocess as

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;
}

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

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

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

Several methods of implementing Linux shell calls under QT

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.