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? :o
QProcess::started () or QProcess::state ()
Re: How to check if a program is running?
What program? "Current" program, arbitrary program or a program started with QProcess?
Re: How to check if a program is running?
Hi,
I am starting a process:
Code:
QString program
= "psexec.exe \\\\stchps426 -c -e -f -n 6 i:\\WinZip8.1.exe";
process->start(program);
This exe runs between 5 seconds and one minute.
I have to wait until this exe stop to make some job
Re: How to check if a program is running?
Rely on signals then. You'll get notified when the process is started and finished.
Re: How to check if a program is running?
Hi Wysota,
thanks
i solved with QProcess::waitForFinished :)
Re: How to check if a program is running?
oh,
this function is blocking my app :crying:
Have i another posibility to check if a exe is running?
Re: How to check if a program is running?
Yes, read my previous post again.
Re: How to check if a program is running?
I dont know how to implement..
Where can i find a example? :o
Re: How to check if a program is running?
QProcess has the following signal
Code:
void finished
(int exitCode,
QProcess::ExitStatus exitStatus
)
And you can connect it to your slot
Code:
connect(yourProcess,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(yourSlot
(int,
QProcess::ExitStatus)));
and then implement your slot
Code:
void yourClass
::yourSlot(int exitCode,
QProcess::ExitStatus exitSatus
) {
// your code
}
Re: How to check if a program is running?
hi everybody,
what is wrong:
.h:
Code:
#include "ui_mainwindow.h"
#include <QProcess>
{
Q_OBJECT
public:
MainWindow();
public slots:
void yourSlot
(int *exitCode,
QProcess::ExitStatus *exitSatus
);
private:
Ui::PushFast ui;
};
.cpp:
Code:
MainWindow::MainWindow()
{
ui.setupUi(this);
connect(*process,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(yourSlot
(int,
QProcess::ExitStatus)));
}
void MainWindow
::yourSlot(int *exitCode,
QProcess::ExitStatus *exitSatus
) {
QMessageBox::information(this,
"",
"process finished");
}
void MainWindow::startpsexec()
{
QString username
= ui.
username_le->text
();
QString password
= ui.
password_le->text
();
QString hostname
= ui.
hostname_le->text
();
QString software
= ui.
software_cb->currentText
();
QString path
= ui.
source_path_cb->currentText
();
//Installieren
//QProcess *process = new QProcess(this);
QString program
= "psexec.exe \\\\" + hostname
+ " -u " + hostname
+ "\\" + username
+ " -p " + password
+ " -i -c -e -f -n 6 " + zeichen
+ path
+ "\\" + software
+ zeichen;
process->start(program);
QString information
= process
->readAllStandardError
();
information.replace(0, 126, "");
information.replace("with error code 0.", "");
}
Re: How to check if a program is running?
Quote:
Originally Posted by
raphaelf
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).
Re: How to check if a program is running?
Quote:
Originally Posted by
raphaelf
hi everybody,
what is wrong:
Code:
public slots:
void yourSlot
(int *exitCode,
QProcess::ExitStatus *exitSatus
);
Code:
connect(*process,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(yourSlot
(int,
QProcess::ExitStatus)));
Those signatures don't match.
Re: How to check if a program is running?
Hi all,
thanks very much it works :p
Re: How to check if a program is running?
Quote:
Originally Posted by
raphaelf
Hi all,
thanks very much it works :p
why my source code error?
http://www.mediafire.com/?kdryz5tyozj
Code:
#include "widgetcheckprocess.h"
#include <QMessageBox>
WidgetCheckProcess
::WidgetCheckProcess(QWidget *parent, Qt
::WFlags flags
): QMainWindow(parent, flags
){
ui.setupUi(this);
StartProcess("I:/SoftWare_Install/wincmp-setup.exe");
connect(qpProcess,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(SlotDetectFinish
(int,
QProcess::ExitStatus)));
}
WidgetCheckProcess::~WidgetCheckProcess()
{
}
void WidgetCheckProcess
::StartProcess(QString qsProcessPath
) {
qpProcess->startDetached(qsProcessPath);
qpProcess->waitForFinished();
}
void WidgetCheckProcess
::SlotDetectFinish(int *exitCode,
QProcess::ExitStatus *exitSatus
) {
QMessageBox::information(this,
"",
"process finished");
}
Code:
#ifndef WIDGETCHECKPROCESS_H
#define WIDGETCHECKPROCESS_H
#include <QtGui/QMainWindow>
#include "ui_widgetcheckprocess.h"
#include <QProcess>
{
Q_OBJECT
public:
WidgetCheckProcess
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~WidgetCheckProcess();
void StartProcess
(QString qsProcessPath
);
public slots:
void SlotDetectFinish
(int *exitCode,
QProcess::ExitStatus *exitSatus
);
//signals:
// void finished(int exitCode, QProcess::ExitStatus exitStatus);
private:
Ui::WidgetCheckProcessClass ui;
};
#endif // WIDGETCHECKPROCESS_H
Code:
#include "widgetcheckprocess.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
WidgetCheckProcess w;
w.show();
return a.exec();
}
Re: How to check if a program is running?
Re: How to check if a program is running?
Quote:
Originally Posted by
raphaelf
Hi all,
thanks very much it works :p
you can help me,why i use SIGNAL(finished(int, QProcess::ExitStatus) like you but cant run
http://www.mediafire.com/?kdryz5tyozj
Re: How to check if a program is running?
Please re-read wysota's post and stop duplicating your posts.