Results 1 to 4 of 4

Thread: I start a external fortram program, how to terminate?

  1. #1
    Join Date
    Aug 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default I start a external fortram program, how to terminate?

    i have created MyThread, subclass QThread and reimplement run(),
    class MyThread : public QThread
    {
    Q_OBJECT
    public:
    void run();
    void stop();
    private:
    QProcess *MyProcess;
    };

    MyThread::MyThread(QWidget *parent )
    {
    MyProcess = new QProcess(parent);
    }

    void MyThread::run()
    {
    MyProcess->execute("ComputerFortran"); //call for Fortran computer program
    }

    void MyThread::stop()
    {
    MyProcess->kill(); // or
    // MyProcess->terminate();
    }
    when i start external fortran program ,i call start() function.

    Quote:

    class ...............
    {...........
    MyThread thread;
    ............
    };

    .....................
    thread.start();

    but I call thread.stop(), the fortran program didn't kill? how to terminate??

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: I start a external fortram program, how to terminate?

    You don't need a thread to run QProcess. It only makes things unnecessarily more complex. QProcess runs an external process, which doesn't block the main application anyhow unless you call one of the QProcess::wait*() methods (or QProcess::execute() which waits the process to finish). Instead, just start it and connect to its signals to get notified when something interesting happens:
    Qt Code:
    1. process = new QProcess(this);
    2. connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
    3. connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processOutput(int, QProcess::ExitStatus)));
    4. process->start("ComputerFortran");
    5.  
    6. void MyClass::processError(QProcess::ProcessError error)
    7. {
    8. ...
    9. }
    10.  
    11. void MyClass::processOutput(int exitCode, QProcess::ExitStatus exitStatus)
    12. {
    13. ....
    14. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I start a external fortram program, how to terminate?

    Thanks Jpn !!

    the external fortran program will take several hours on outputting 100 data files, I think I

    will kill the fortran program when I have found errors in first 10 data files, that's to say, the

    fortran program process have not finish, how to terminate the fortran process?


    By the way, I want to know how to display terminal characters in QLabal or QEditin in real time ?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: I start a external fortram program, how to terminate?

    Quote Originally Posted by dolphins View Post
    the external fortran program will take several hours on outputting 100 data files, I think I

    will kill the fortran program when I have found errors in first 10 data files, that's to say, the

    fortran program process have not finish, how to terminate the fortran process?
    Since terminate() has no effect, you might have to kill() it. Earlier the situation was kind of problematic since you were commanding the process from multiple threads but it should work fine after you do the proposed changes.

    By the way, I want to know how to display terminal characters in QLabal or QEditin in real time ?
    QProcess emits readyReadStandardError() and/or readyReadStandardOutput() when there is something available to read.
    J-P Nurmi

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  3. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.