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. Kill an application running outside a GUI with QProcess
Forum Updated to NodeBB v4.3 + New Features

Kill an application running outside a GUI with QProcess

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • L Offline
    L Offline
    leandrogs
    wrote on last edited by
    #1

    Hello guys!

    I have created a GUI where, one of your functions, is to run an application called TerraME with QProcess. The problem is that i have to put at the GUI an button for the user stop this application, but my GUI is unable to interact with the user when the TerraME is still running.

    Here follows part of my code:

    @
    QProcess program;
    QStringList parameters;

    parameters << this->workspace + "/coupled/coupled_model.lua";
    
    program.start("TerraME", parameters);
    
    if(!program.waitForStarted()){
        if(QMessageBox::Yes == QMessageBox::question(this, tr("TerraME is not configured"),
                                                     tr("TerraME is not defined as a environment variable. Do you wanna select your executable?"),
                                                     QMessageBox::Yes|QMessageBox::No)){
            QString terraPath = configureTerraME();
            program.start(terraPath, parameters);
        } else {
            QMessageBox::information(this, tr("Process canceled"), tr("Process canceled by user"));
    

    // this->ui->textBrowser->clear();
    return "";
    }
    }

    program.waitForFinished(-1);
    
    QString outputOk(program.readAllStandardOutput());
    QString outputErr(program.readAllStandardError());
    QString output = outputOk + outputErr;
    
    return output;@
    

    This "return output" is just to show the errors and the application output at my GUI.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Because QProcess::waitForFinished() will block your program ;-)

      Instead of calling that on, use Singals & Slots and connect your slot to the finished() signal of QProcess.

      This way, you application stay responsive while the process is running and still react when it finishes.

      Also, instead of readAllStandardOutput() once, better connect to the readyReadStandardOutput() signal...

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leandrogs
        wrote on last edited by
        #3

        [quote author="MuldeR" date="1366233632"]Because QProcess::waitForFinished() will block your program ;-)

        Instead of calling that, use Singals & Slots and connect your slot to the finished() signal of QProcess.[/quote]

        Does you have any example code for that?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          It's straight forward, if you are familiar with the concept of Singals & Slots.

          So you probably want to start here:
          http://qt-project.org/doc/qt-4.8/signalsandslots.html

          And then see here:
          http://qt-project.org/doc/qt-4.8/qprocess.html#signals

          --

          More extensive example:
          https://github.com/lordmulder/LoggingUtil/blob/master/src/LogProcessor.cpp

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          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