February 16, 2011

MrDeathNote MrDeathNote
Lab Rat
3 posts

(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:

  1. QProcess *engine = new QProcess(this);
  2. QString path("C:\\sandbox\\Engine_win\\dist\\Release\\MinGW-Windows");
  3. engine->setWorkingDirectory(path);
  4. QString program = "\"" + path + "\\engine_win.exe\"";
  5. engine->start(program);
  6.  
  7. //Error checking
  8. if(engine->waitForStarted(2000) == true)
  9. {
  10.     qDebug() << "running";
  11. }

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.

7 replies

February 16, 2011

Volker Volker
Ant Farmer
5331 posts

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?

February 17, 2011

MrDeathNote MrDeathNote
Lab Rat
3 posts

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.

February 17, 2011

hakan hakan
Lab Rat
5 posts

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

February 17, 2011

MrDeathNote MrDeathNote
Lab Rat
3 posts

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.

February 17, 2011

Volker Volker
Ant Farmer
5331 posts

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

February 17, 2011

sven.bergner sven.bergner
Lab Rat
9 posts

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

 Signature 

Coding less and creating more with every new version of Qt a bit more.

February 17, 2011

MrDeathNote MrDeathNote
Lab Rat
3 posts

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.

 
  ‹‹ SQL: How to insert a new record in a QSqlRelationalTableModel      QNetworkAccessManager::networkAccessible() trigger ››

You must log in to post a reply. Not a member yet? Register here!