2009年6月10日 星期三

qt執行外部指令


Qt要執行外部指令,可用Qprocess
ui->comboBox->currentIndex()取得comboBox的Index是一個int
還用到switch函式

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qprocess>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_pressed()
{
QString str;
int a;
a=ui->comboBox->currentIndex();
switch (a) { //switch敘述
case 0 : str="/home/tools/laker/bin/laker &" ; break ;
case 1 : str="/home/yplin66/.SH/home_sell/calibre2008-gui &" ; break ;
}
QProcess *myP = new QProcess(this); //宣告QProcess
myP->start(str);
}




來一個例子,當我選單,選laker時,按下確定紐,就可執行laker,如下圖


沒有留言: