Results 1 to 4 of 4

Thread: Qt start new application and quit

  1. #1
    Join Date
    Jan 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt start new application and quit

    Hello! I posted my issue on stackoverflow: http://stackoverflow.com/questions/2...93521_27736976
    I have no idea how to run other application in background from main application. Every time main application is quitting, applications started by it are closed too.

    I have tried to use Q_DESTRUCTOR_FUNCTION to run process after main() is processing, without result. I also tried a lot of function:

    Qt Code:
    1. void closeApp()
    2. {
    3. QProcess test;
    4. if(test.startDetached("cmd.exe &"))
    5. qDebug() << "Running";
    6. QProcess::execute("cmd.exe");
    7. system("start cmd.exe &");
    8. system("cmd.exe &");
    9. execl("start cmd.exe", "ls", "-r", "-t", "-l", (char *) 0);
    10. system("cmd.exe");
    11. FILE* pd = popen("cmd.exe &", "r");
    12. }
    13.  
    14. Q_DESTRUCTOR_FUNCTION(closeApp)
    To copy to clipboard, switch view to plain text mode 

    Is it possible to launch and keep process by running from main application?
    edit: ok, the problem was debugger .. outside it all works great with simple QProcess::startDetached("xxx");
    Last edited by TheQuake; 4th January 2015 at 00:39.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt start new application and quit

    Yes, it is possible using QProcess::startDetached() and passing it a path to a valid executable and optionally arguments and a working directory.
    This code works just fine:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QProcess>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char **argv) {
    6. QCoreApplication app(argc, argv);
    7.  
    8. bool ok = QProcess::startDetached("notepad.exe");
    9. qDebug() << ok;
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    with a Windows notepad left running after program exit.

  3. #3
    Join Date
    Jan 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt start new application and quit

    Yeah you're right, but this works only outside debugger. If you try to debug it, it won't work.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt start new application and quit

    It works fine here when run in the Gnu Debugger (Qt 4.8.4 MingW)

Similar Threads

  1. Correct way to quit a console application
    By c1223 in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2014, 20:51
  2. Replies: 2
    Last Post: 1st August 2011, 07:30
  3. Replies: 1
    Last Post: 28th July 2011, 10:10
  4. Application won't quit until event loop quits
    By caelestis in forum Qt Programming
    Replies: 6
    Last Post: 11th February 2010, 08:21
  5. Why my application quit?
    By yxtx1984 in forum Newbie
    Replies: 1
    Last Post: 7th February 2010, 06:46

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.