Results 1 to 17 of 17

Thread: How to check if a program is running?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  2. #2
    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).

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

  4. #4
    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

  5. #5
    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 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  7. #7
    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

  8. #8
    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
  •  
Qt is a trademark of The Qt Company.