Tryin to run an executable from a click of a pushbutton
-
Hi there, I am new to QT Creator, I am currently trying to run an executable file with a click of a button, what keeps happening is that it runs the executable but only on the application output tab and not independently outside of QT, how do I make sure that it runs by itself?
void MainWindow::on_pushButton_3_clicked()
{QString botDirectory = QDir::currentPath() + "/BOTS"; QString botFolderPath = botDirectory + "/" + selectedBot; QDir botDir(botFolderPath); QStringList exeFiles = botDir.entryList(QStringList() << "*.exe", QDir::Files); if (exeFiles.isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("No executable found in the bot folder.")); return; } QString botExecutablePath = botFolderPath + "/" + exeFiles.first(); QString machineIDPath = botFolderPath + "/MachineID.txt"; // Debug: Print paths qDebug() << "Bot Folder Path: " << botFolderPath; qDebug() << "Bot Executable Path: " << botExecutablePath; qDebug() << "MachineID Path: " << machineIDPath; if (!QFile::exists(machineIDPath)) { qDebug() << "MachineID.txt file does not exist."; QMessageBox::critical(this, tr("Error"), tr("MachineID.txt file not found in the bot folder.")); return; } qDebug() << "Attempting to start bot executable:" << botExecutablePath; // Start the process detached qint64 pid; bool success = QProcess::startDetached(botExecutablePath, QStringList(), botFolderPath, &pid); if (!success) { // Handle error if the process did not start QMessageBox::critical(this, tr("Error"), tr("Failed to start the executable.")); } else { // Handle success if the process started qDebug() << "Executable started:" << botExecutablePath; }
}
^ This is my code, the executable itself runs properly from File Explorer, and the paths are configured properly all I need is for it to run on its own, any help?
-
Hi and welcome to devnet,
What exactly are you seeing ?
Is it a command line application ?
What do you mean by "only on the application output" ?