我的做法如下:
1.使用c之execl函式庫呼叫ls –al(請參旗標Linux函式庫13-5)
2.再用C++包起來
3.使用</usr/include/unistd.h>而非<unistd.h>請參考
viewtopic.php?t=4871
程式如下:希望能對你有所助益
//main.cpp
#include <qapplication.h>
#include "test.h"
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
CTest *test=new CTest();
test->move(200, 100);
test->show();
app.setMainWidget(test);
return app.exec();
}
//test.h
#ifndef TEST_H
#define TEST_H
#include <qwidget.h>
class CTest : public QWidget
{
Q_OBJECT
public:
CTest(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
private slots:
void execfile();
};
#endif
//test.cpp
#include <qpushbutton.h>
#include </usr/include/unistd.h>
#include "test.h"
void CTest::execfile()
{
execl("/bin/ls","ls","-al",(char *)0);
}
CTest::CTest(QWidget *parent, const char *name, WFlags f ) : QWidget( parent, name, f)
{
QPushButton *button = new QPushButton("Test", this);
QObject::connect(button, SIGNAL(clicked()), SLOT(execfile()));
}
allanyueh@yahoo.com.tw若有錯誤還望指正