Results 1 to 9 of 9

Thread: Problems launching a windows exe from Qt (using QProcess)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems launching a windows exe from Qt (using QProcess)

    I didn't realize that setting the path wouldn't impact the process - thanks for that info. When I pass the full path including the executable to ::start, it doesn't get parsed correctly. I also tried the following, which resulted in the same problem:
    Qt Code:
    1. String path("C:\\Program Files\\My Company\\MyCompanyMonitor");
    2.  
    3. QString fullPath = "\"" + path + "\\Monitor.exe\"";
    4.  
    5. bool ok = QProcess::startDetached(
    6. fullPath,
    7. "\"" + path + "\"");
    8.  
    9. if (!ok)
    10. {
    11. QMessageBox::critical(
    12. NULL, QString(), tr("Unable to run the Control Panel\n"));
    13. }
    To copy to clipboard, switch view to plain text mode 

    Note that I'm passing the full path. It still won't start the program

    I'll try switching to "/" and get back to (this always worked on Linux!).

    Thanks

  2. #2
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems launching a windows exe from Qt (using QProcess)

    Ok, I tried changing "\\" to "/". I tried adding "C:\\Program Files\\My Company\\MyCompanyMonitor" to the system path, restarted a command prompt and made sure the system path change worked (i.e., can I simply type "Monitor" and have it run) - and it worked.

    But my application still can't launch the executable...this is REALLY frustrating and puzzling. I've debugged into QProcess code and can't seem to find why CreateProcess fails... I'm not a windows guru, but it seems to me that this should work...

    Any help is greatly appreciated.

    Thanks

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems launching a windows exe from Qt (using QProcess)

    Maybe the file can be found, but can't be run? It could be failing to find a dependancy. If your debugging into QProcess code, you should post the result from GetLastError() after the CreateProcess. Even better, you could go here -> http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx and look up the error code.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems launching a windows exe from Qt (using QProcess)

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems launching a windows exe from Qt (using QProcess)

    I managed to figure out the problem! I had to include the path to the program AND include quotes around it. And the working directory had to be correct in that it had to include "\" not "/" or create process returned invalid directory. So the working code looks like:
    Qt Code:
    1. if (_mon)
    2. return;
    3.  
    4. _mon = new QProcess(this);
    5.  
    6. QString path("C:\\Program Files\\My Company\\MyMonitor");
    7.  
    8. _mon->setWorkingDirectory(path);
    9.  
    10. QString program = "\"" + path + "/Monitor.exe" + "\"";
    11. _mon->start(program);
    12. ...
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Problems launching a windows exe from Qt (using QProcess)

    I have encountered the same problem. The solution smacchia described works, although it is a little messy (it produces ""C:\\Program Files\\My Company\\MyMonitor/Monitor.exe"" as a path, with the quotes). The way I found it to work and also look nicer is to set the working directory to the directory of the application to launch and then simply call start("myapplication.exe").

    Qt Code:
    1. QProcess* process = new QProcess(this);
    2. process->setWorkingDirectory(path_of_application);
    3. process->start("application.exe");
    To copy to clipboard, switch view to plain text mode 

    I believe this shouldn't be necessary and it should run with the full path. This might be a bug, though I'm not sure about the exact circumstances yet. It may worth mentioning that the application I'm launching is a .NET application.

Similar Threads

  1. QProcess::finished problems again
    By mdicosimo in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 21:43
  2. Windows focus / Windows Shutdown Problems
    By December in forum Qt Programming
    Replies: 6
    Last Post: 22nd October 2007, 14:10
  3. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  4. need help for QProcess under windows
    By patcito in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2006, 19:54
  5. Qprocess never end in MS windows
    By antonio.r.tome in forum Qt Programming
    Replies: 12
    Last Post: 23rd February 2006, 12:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.