I have a windows qt application and I’m trying to open an external game, but I’m not having success.
Application is in C:\games\Oni\Edition\ and is called Oni.exe, the code I’m using right now is the follow:
void MainWindow::on_toolButton_clicked()
{
qint64 test=1;
if(!QProcess::startDetached("Oni.exe",QStringList(),"C:\\games\\Oni\\Edition\\",&test)){
QMessageBox msgBox;
msgBox.setText("Oni couln't be started!");
msgBox.exec();
}
}
I don’t know if I’m forgetting something? The game runs fine if I double click it. Thanks.
Alright, figured it out.
Just replaced the code:
by
And it’s working like a charm.
I had also tried
QProcess::startDetached("C:\\games\\Oni\\Edition\\Oni.exe");before but didn’t worked, seems we need to put always the full directory of the executable and also the full directory as working directory. This because seems only executing the file directly, the file itself may be looking for another folders/files in the QT Debug folder, when they are in the game folder. This cause the game quits prematurely. 🙂Another solution would be use windows native api like user827992 pointed out in the follow link: QProcess::startDetached blocked by UAC (running an updater)
This latter solution also should work fine with UAC problems.