haulm 发表于 2008-3-9 12:55:05

基础篇 -- 使用QProcess和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();
}


[ 本帖最后由 haulm 于 2008-3-9 12:57 编辑 ]

lanzinc 发表于 2008-3-9 17:10:13

to haulm:
你的这几篇都是具体应用的,有没有详细介绍Qt的,
比如Qt类库的结构
没个类的属性和方法
和他们的作用

还有Qt的信号机制的

haulm 发表于 2008-3-9 20:33:08

这个应该去看pdf格式的《24学时Qt编程》以及公社早前我有收集汤坤的60页的Qt4图片教程。虽然《24学时Qt编程》讲的是Qt3编程,但配合Qt4助手还是不错的。虽然Qt3和Qt4有很大差别,但基础内容还是差不多的。

gxglhyy 发表于 2008-3-10 13:04:38

为什么还要用 QThread ?直接调用 QProcess::execute 就可以了

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

haulm 发表于 2008-3-10 15:12:01

是的,但是这类的编程肯定要用到 QThread ,这样会更好一些。

lsyer 发表于 2008-3-10 17:11:58

尤其在要等待一个事务结束后才能执行另一个的顺序型。
页: [1]
查看完整版本: 基础篇 -- 使用QProcess和QThread运行外部指令