Opening command shell when starting a Qprocess
-
Hi,
I have made a .exe file that I normally run on Windows command line, and I want to run it from my Qt GUI. I think I manage to run it, but I am not sure as there is no window popping up. I would love to have a command line window appearing and all the couts printed on it when I launch my Qprocess.. hopefully this is possible?Here is how I setup a path to the exe file I want to run, and how I start a qprocess from it afterwards (with a choose path button, and a lauch exe button):
void MainWindow::on_jackExe_path_pushButton_clicked() { _exePath = QFileDialog::getOpenFileName(); ui->jackExe_path_label->setText(_exePath);
void MainWindow::on_json_launch_pushButton_clicked() { if(_exePath != "") { for(int i = 0; i < _testQueue.size(); i++) { QStringList arguments; arguments << "-json" << _testQueue[0].GetFileName(); arguments << "-port" << ui->comPort_comboBox->currentText(); arguments << "-help"; qDebug() << arguments; _exeProcess->QProcess::start(_exePath, arguments); //I can't see any window! but no error message from Qt _testQueue.removeAt(0); RefreshJsonListWidget(); } } else { qDebug() << "No Path selected!"; QMessageBox::critical(this, tr("Error"), tr("No path chosen for Jacky.exe")); } }
How can I open a shell window that runs the Jacky.exe file? Thanks a lot!
-
Hi and welcome to devnet,
Unless your command line application explicitly creates a new command line window, this won't happen.
However, QProcess provides everything your need to read the output generated by your command. For example, QProcess::readyReadStandardOutput that lets you know there's something to read.
-
First you loop does not work at all:
for(int i = 0; i < _testQueue.size(); i++) { .. _testQueue.removeAt(0); }
Only half of your elements are taken.
Second you have to wait until the process is finished until starting it again. And no you should not use QProcess::waitForFinished() but signals and slots.
-
@Christian-Ehrlicher Thanks! I have removed the loop for now like so:
void MainWindow::on_json_launch_pushButton_clicked() { if(_exePath != "") { // for(int i = 0; i < _testQueue.size(); i++) // { QStringList arguments; arguments << "-json" << _testQueue[0].GetFileName(); arguments << "-port" << ui->comPort_comboBox->currentText(); arguments << "-help"; qDebug() << arguments; _exeProcess->QProcess::start(_exePath, arguments); _testQueue.removeAt(0); RefreshJsonListWidget(); // } } else { qDebug() << "No Path selected!"; QMessageBox::critical(this, tr("Error"), tr("No path chosen for Jacky.exe")); } }
as I would like to focus on the command line window problem. I tried running it without the loop, just to see if it would appear if I called a single file, but it doesn't
-
Hi and welcome to devnet,
Unless your command line application explicitly creates a new command line window, this won't happen.
However, QProcess provides everything your need to read the output generated by your command. For example, QProcess::readyReadStandardOutput that lets you know there's something to read.