MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::on_addExeButton_clicked()
{
QString filename
= QFileDialog::getOpenFileName(this, tr
("Choose the application"), tr
("."), tr
("Excutable(*.exe)"));
if(filename.isNull())
return false;
//user choose an excutive application
QIcon icon
= seekIcon.
icon(fileInfo
);
btn->resize( 300, 300);
btn->setIcon(icon);
//if user click the corresponding button, this app will run the chosen application
connect(btn, SIGNAL(clicked()), this, SLOT(callExe()));
buttons.insert(filename, btn);
ui->verticalLayout1->addWidget(btn);
ui->verticalLayout1->addStretch();
}
void MainWindow::callExe()
{
qDebug() << "Ready to execute program";
QToolButton *sender
= static_cast<QToolButton
*>
(this
->sender
());
while(i.hasNext())
{
if(i.peekNext().value() == sender)
{
path = i.next().key();
qDebug() << "Find the path!!\n";
break;
}
}
if(path.isEmpty())
{
qDebug() << "******File path is null!!";
return;
}
//run the corresponding application
// QObject *parent = NULL;
// QString program = "J:\\2\\exeshan\\Debug\\11.ppt";
arguments << "-style" << "motif";
myProcess->start(path, arguments);
connect(myProcess,
SIGNAL(error
(QProcess::ProcessError)),
this,
SLOT(badProcess
(QProcess::ProcessError)));
qDebug() << "SLOT successfully!" << endl;
}
void MainWindow
::badProcess(QProcess::ProcessError error
) {
qDebug() << "Process error!!" << error;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::on_addExeButton_clicked()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Choose the application"), tr("."), tr("Excutable(*.exe)"));
if(filename.isNull())
return false;
//user choose an excutive application
QFileInfo fileInfo(filename);
QFileIconProvider seekIcon;
QIcon icon = seekIcon.icon(fileInfo);
QToolButton *btn = new QToolButton;
btn->resize( 300, 300);
btn->setIcon(icon);
//if user click the corresponding button, this app will run the chosen application
connect(btn, SIGNAL(clicked()), this, SLOT(callExe()));
buttons.insert(filename, btn);
ui->verticalLayout1->addWidget(btn);
ui->verticalLayout1->addStretch();
}
void MainWindow::callExe()
{
qDebug() << "Ready to execute program";
QToolButton *sender = static_cast<QToolButton*>(this->sender());
QString path;
QMapIterator<QString, QToolButton *> i(buttons);
while(i.hasNext())
{
if(i.peekNext().value() == sender)
{
path = i.next().key();
qDebug() << "Find the path!!\n";
break;
}
}
if(path.isEmpty())
{
qDebug() << "******File path is null!!";
return;
}
//run the corresponding application
// QObject *parent = NULL;
// QString program = "J:\\2\\exeshan\\Debug\\11.ppt";
QStringList arguments;
arguments << "-style" << "motif";
QProcess *myProcess = new QProcess(this);
myProcess->start(path, arguments);
connect(myProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(badProcess(QProcess::ProcessError)));
qDebug() << "SLOT successfully!" << endl;
}
void MainWindow::badProcess(QProcess::ProcessError error)
{
qDebug() << "Process error!!" << error;
}
To copy to clipboard, switch view to plain text mode
Bookmarks