PDA

View Full Version : opening a batch file from Qt



Aashu10
23rd November 2015, 11:55
i want to run a bacth file from QT, currently i have code something like given below. i want to run on cmd is somthing like

startup.bat -arg1=abc -arg2=abc1 -arg2=abc3 -arg4=abc4

how do i run the batch file with arguments? any help will be appriciated





void MainWindow::on_Button_Go_clicked()
{
QProcess cmd;
const QString myProc = "cmd.exe /c startup.bat " + MainWindow::getWorkingConfiguration(); QString sOldPath = QDir::currentPath();
QString myPath= MainWindow::getWorkingDirectory();
QDir::setCurrent( myPath );

//Run it!
cmd.startDetached(myProc);
qDebug(myPath.toStdString().c_str());

QDir::setCurrent( sOldPath );
}

anda_skoa
23rd November 2015, 13:22
Your myProc variable is wrong, it contains the program to run and the arguments instead of just the program.

The "program" argument to any of the QProcess start methods is just the program, arguments get passed using the "arguments" argument.

Cheers,
_