Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (Solved)Problems lauching .exe with QProcess
Qt 6.11 is out! See what's new in the release blog

(Solved)Problems lauching .exe with QProcess

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 8.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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");
    engine->setWorkingDirectory(path);
    QString program = """ + path + "\engine_win.exe"";
    engine->start(program);

    //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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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?
      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved