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. How can I start an application that will live on after the caller app has finished?
Forum Updated to NodeBB v4.3 + New Features

How can I start an application that will live on after the caller app has finished?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 279 Views
  • 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.
  • aarelovichA Offline
    aarelovichA Offline
    aarelovich
    wrote on last edited by
    #1

    This is what I wanted to do.

    I have a script that currently just starts prints a message. Waits 5 seconds and prints another message before finishing by asking the user to press any key to end.

    And I have a Qt application that needs to call this script and then quit. I want the console window to open up to display and the script text and this new process to be able to continue after the Qt appliction has finished.

    In windows my script is called "update.bat"

    So I have tried:

    QProcess::startDetached("update.bat");
    QCoreApplication::quit();
    but the console (windows one) does NOT open up (all output is in QtCreator) and it definitely does not continue after the application is finished.

    Is there a way to do this using Qt?

    I don't want to rely on the CreateProcess from windows, if possible, and use Qt soloution.

    I have also tried the setCreateProcessArgumentModifier and to start the update.bat script with cmd /k. The results for all of this is exactly the same. Output is redirected to the QtCreator console and when executing the application outside of Qt nothing happens (this is all happens when you press a button).

    QProcess p;
    //    QProcess process;
    //    process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args)
    //    {
    //        args->flags |= CREATE_NEW_CONSOLE;
    //        args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
    //        args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
    //        args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
    //                                           | FOREGROUND_INTENSITY;
    //    });
    // process.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");
        p.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");
    

    Finally I have tried using system. Like this:

    system(QString("update.bat").toStdString().c_str());
    

    The problem with this is that it's blocking. So I can't quit the application. And If I try to terminate it from the script it doesn't die until the script is done.

    Any other suggestions?

    KroMignonK 1 Reply Last reply
    0
    • aarelovichA aarelovich

      This is what I wanted to do.

      I have a script that currently just starts prints a message. Waits 5 seconds and prints another message before finishing by asking the user to press any key to end.

      And I have a Qt application that needs to call this script and then quit. I want the console window to open up to display and the script text and this new process to be able to continue after the Qt appliction has finished.

      In windows my script is called "update.bat"

      So I have tried:

      QProcess::startDetached("update.bat");
      QCoreApplication::quit();
      but the console (windows one) does NOT open up (all output is in QtCreator) and it definitely does not continue after the application is finished.

      Is there a way to do this using Qt?

      I don't want to rely on the CreateProcess from windows, if possible, and use Qt soloution.

      I have also tried the setCreateProcessArgumentModifier and to start the update.bat script with cmd /k. The results for all of this is exactly the same. Output is redirected to the QtCreator console and when executing the application outside of Qt nothing happens (this is all happens when you press a button).

      QProcess p;
      //    QProcess process;
      //    process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args)
      //    {
      //        args->flags |= CREATE_NEW_CONSOLE;
      //        args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
      //        args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
      //        args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
      //                                           | FOREGROUND_INTENSITY;
      //    });
      // process.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");
          p.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");
      

      Finally I have tried using system. Like this:

      system(QString("update.bat").toStdString().c_str());
      

      The problem with this is that it's blocking. So I can't quit the application. And If I try to terminate it from the script it doesn't die until the script is done.

      Any other suggestions?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @aarelovich said in How can I start an application that will live on after the caller app has finished?:

      p.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");

      To start a detached process with Windows system, you could try this:
      p.start("cmd.exe", QStringList() << "/c" << "start" << "update.bat"),

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      aarelovichA 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @aarelovich said in How can I start an application that will live on after the caller app has finished?:

        p.startDetached("cmd.exe",QStringList() << "/k" << "update.bat");

        To start a detached process with Windows system, you could try this:
        p.start("cmd.exe", QStringList() << "/c" << "start" << "update.bat"),

        aarelovichA Offline
        aarelovichA Offline
        aarelovich
        wrote on last edited by
        #3

        @KroMignon said in How can I start an application that will live on after the caller app has finished?:

        p.start("cmd.exe", QStringList() << "/c" << "start" << "update.bat"),

        When I tried the Qt Creator console (no reaction when exectuting stand alone) printed this:

        QProcess: Destroyed while process ("cmd.exe") is still running.
        

        I actually found a work around for this which it spawn a separate thread then use system to call the script and finally have the script itself kill the application.

        For what I want that's good enough. Thank you anyways.

        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