Results 1 to 17 of 17

Thread: How to check if a program is running?

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Red face How to check if a program is running?

    Hi everybody,

    how could i check if a program is running?

    I think one of following functions is what i am searching, but i have not found a example and i dont know how to check if a program is running..

    Can somebody make a example for me?
    QProcess::started () or QProcess::state ()
    Think DigitalGasoline

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

    Default Re: How to check if a program is running?

    What program? "Current" program, arbitrary program or a program started with QProcess?

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Red face Re: How to check if a program is running?

    Hi,

    I am starting a process:
    Qt Code:
    1. QProcess *process = new QProcess(this);
    2. QString program = "psexec.exe \\\\stchps426 -c -e -f -n 6 i:\\WinZip8.1.exe";
    3. process->start(program);
    To copy to clipboard, switch view to plain text mode 

    This exe runs between 5 seconds and one minute.

    I have to wait until this exe stop to make some job
    Last edited by raphaelf; 23rd June 2008 at 12:35.
    Think DigitalGasoline

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

    Default Re: How to check if a program is running?

    Rely on signals then. You'll get notified when the process is started and finished.

  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check if a program is running?

    Hi Wysota,

    thanks

    i solved with QProcess::waitForFinished
    Think DigitalGasoline

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check if a program is running?

    oh,

    this function is blocking my app

    Have i another posibility to check if a exe is running?
    Think DigitalGasoline

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

    Default Re: How to check if a program is running?

    Yes, read my previous post again.

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check if a program is running?

    I dont know how to implement..

    Where can i find a example?
    Think DigitalGasoline

  9. #9
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to check if a program is running?

    QProcess has the following signal
    Qt Code:
    1. void finished(int exitCode, QProcess::ExitStatus exitStatus)
    To copy to clipboard, switch view to plain text mode 

    And you can connect it to your slot

    Qt Code:
    1. connect(yourProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(yourSlot(int, QProcess::ExitStatus)));
    To copy to clipboard, switch view to plain text mode 

    and then implement your slot
    Qt Code:
    1. void yourClass::yourSlot(int exitCode, QProcess::ExitStatus exitSatus)
    2. {
    3. // your code
    4. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  10. #10
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check if a program is running?

    hi everybody,

    what is wrong:

    .h:
    Qt Code:
    1. #include "ui_mainwindow.h"
    2. #include <QProcess>
    3.  
    4.  
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow();
    12.  
    13.  
    14. public slots:
    15. void yourSlot(int *exitCode, QProcess::ExitStatus *exitSatus);
    16.  
    17.  
    18. private:
    19. Ui::PushFast ui;
    20. };
    To copy to clipboard, switch view to plain text mode 

    .cpp:
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ui.setupUi(this);
    4. QProcess *process = new QProcess(this);
    5. connect(*process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(yourSlot(int, QProcess::ExitStatus)));
    6.  
    7. }
    8.  
    9. void MainWindow::yourSlot(int *exitCode, QProcess::ExitStatus *exitSatus)
    10. {
    11. QMessageBox::information(this, "", "process finished");
    12. }
    13.  
    14. void MainWindow::startpsexec()
    15. {
    16. QString username = ui.username_le->text();
    17. QString password = ui.password_le->text();
    18. QString hostname = ui.hostname_le->text();
    19. QString software = ui.software_cb->currentText();
    20. QString path = ui.source_path_cb->currentText();
    21.  
    22.  
    23.  
    24. //Installieren
    25. //QProcess *process = new QProcess(this);
    26. QString zeichen = "\"";
    27. QString program = "psexec.exe \\\\" + hostname + " -u " + hostname + "\\" + username + " -p " + password + " -i -c -e -f -n 6 " + zeichen + path + "\\" + software + zeichen;
    28. process->start(program);
    29. QString information = process->readAllStandardError();
    30. information.replace(0, 126, "");
    31. information.replace("with error code 0.", "");
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to check if a program is running?

    Quote Originally Posted by raphaelf View Post
    process->start(program);
    QString information = process->readAllStandardError();
    You have to give some time to psexec, before you read what it has written. Either connect so readyReadStandardError() signal or use waitForFinished() (note that the latter will hang your application, so it's suitable only if psexec works really fast).

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

    Default Re: How to check if a program is running?

    Quote Originally Posted by raphaelf View Post
    hi everybody,

    what is wrong:

    Qt Code:
    1. public slots:
    2. void yourSlot(int *exitCode, QProcess::ExitStatus *exitSatus);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect(*process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(yourSlot(int, QProcess::ExitStatus)));
    To copy to clipboard, switch view to plain text mode 
    Those signatures don't match.

  13. #13
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check if a program is running?

    Hi all,

    thanks very much it works
    Think DigitalGasoline

  14. #14
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to check if a program is running?

    Quote Originally Posted by raphaelf View Post
    Hi all,

    thanks very much it works
    why my source code error?

    http://www.mediafire.com/?kdryz5tyozj

    Qt Code:
    1. #include "widgetcheckprocess.h"
    2. #include <QMessageBox>
    3. WidgetCheckProcess::WidgetCheckProcess(QWidget *parent, Qt::WFlags flags): QMainWindow(parent, flags)
    4. {
    5. ui.setupUi(this);
    6. qpProcess = new QProcess;
    7. StartProcess("I:/SoftWare_Install/wincmp-setup.exe");
    8. connect(qpProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(SlotDetectFinish(int, QProcess::ExitStatus)));
    9. }
    10. WidgetCheckProcess::~WidgetCheckProcess()
    11. {
    12. }
    13. void WidgetCheckProcess::StartProcess(QString qsProcessPath)
    14. {
    15. qpProcess->startDetached(qsProcessPath);
    16. qpProcess->waitForFinished();
    17. }
    18. void WidgetCheckProcess::SlotDetectFinish(int *exitCode, QProcess::ExitStatus *exitSatus)
    19. {
    20. QMessageBox::information(this, "", "process finished");
    21. }
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. #ifndef WIDGETCHECKPROCESS_H
    2. #define WIDGETCHECKPROCESS_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_widgetcheckprocess.h"
    6. #include <QProcess>
    7. class WidgetCheckProcess : public QMainWindow
    8. {
    9. Q_OBJECT
    10. public:
    11. QProcess *qpProcess;
    12. WidgetCheckProcess(QWidget *parent = 0, Qt::WFlags flags = 0);
    13. ~WidgetCheckProcess();
    14. void StartProcess(QString qsProcessPath);
    15. public slots:
    16. void SlotDetectFinish(int *exitCode, QProcess::ExitStatus *exitSatus);
    17. //signals:
    18. // void finished(int exitCode, QProcess::ExitStatus exitStatus);
    19. private:
    20. Ui::WidgetCheckProcessClass ui;
    21. };
    22.  
    23. #endif // WIDGETCHECKPROCESS_H
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. #include "widgetcheckprocess.h"
    2. #include <QtGui/QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. WidgetCheckProcess w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How to check if a program is running?

    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.


  16. #16
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to check if a program is running?

    Quote Originally Posted by raphaelf View Post
    Hi all,

    thanks very much it works
    you can help me,why i use SIGNAL(finished(int, QProcess::ExitStatus) like you but cant run
    http://www.mediafire.com/?kdryz5tyozj

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

    Default Re: How to check if a program is running?

    Please re-read wysota's post and stop duplicating your posts.

Similar Threads

  1. Help me how to know the program is running
    By vql in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2008, 12:43
  2. Detect platform where my QT4 program is running on
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 12:01
  3. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  4. Check wheter a process is running
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2006, 12:35
  5. Replies: 1
    Last Post: 17th May 2006, 00:23

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.