Important: Please read the Qt Code of Conduct -

(Solved)Problems lauching .exe with QProcess

  • Hey guys this is my first time posting here. I'm writing a toolkit for a game i'm writing and I need to be able to launch the game itself from within the toolkit. I can launch any other program except the game. This is the code i'm using:
    QProcess *engine = new QProcess(this);
    QString path("C:\sandbox\Engine_win\dist\Release\MinGW-Windows");
    QString program = """ + path + "\engine_win.exe"";

    //Error checking
    if(engine->waitForStarted(2000) == true)
    qDebug() << "running";

    The error checking section actually prints running, although i cannot see the process in the task manager and nothing appears on the screen. The engine is written with SDL and OpenGL. I can launch it from the command line with no issues and I can launch any other program using QProcess so I can't see any reason this wouldn't work. If anyone could shed some light on the issue that would be great.

    Edit: Also when i launch the .exe normally (by double clicking) it produces a command prompt which then opens the game window, I don't know if this is relevant but I thought the first window may be timing out before the second is launched.

  • I don't know if it is important, but why do you wrap the command path into quotes (")? Also, forward slashes (/) should work too.

    Regarding your addition:

    • Could it be, that the exe cannot find some dependency? Seems as if it can be started but stops abnormally.
    • Any data on stdout/stderr of the process?
    • Is the new process still running when waitForStarted returns?

  • Thanks for the reply, the reason for the quotes is that some of the paths i was testing this code with had spaces and windows didn't like that. There is no stdout/stderr produced which makes me think that the process doesn't really run at all. I don't think it's because of dependencies if I can run it from the command line it should be ok. And to answer your last question, no it's not still running. In fact there's no way you could tell it started at all, it doesn't appear in the task manager.

  • Have you tried bool QProcess::startDetached ( const QString & program )?

  • I haven't actually tried that yet, I have a few things I actually want to try. I'll get back to you guy's about it. In the mean time if anyone has any other suggestions i'd love to hear about it. Thanks.

  • I would connect some slots to signals started, stateChanged, finished and error and look what's going on.

  • If you don't need to have control over the started process you could use QDesktopServices::openUrl().
    That does something like ShellExecute()

  • I've resolved this now it was because the subsystem was set to console for the engine, meaning the process was running in a background thead without being displayed. Thanks for the help guys.

Log in to reply