Re: Time out for a QProcess?
use QProcess::waitForFinished with a 3 sec timeout and check the condition of QProcess weather it has finished or not. then you can emit the appropriate signal.
Re: Time out for a QProcess?
as you see above i have
Code:
proc.waitForFinished(1000);
and how to know that it has finihed or not while it still runnign in another process
but seem that it does not work well
Re: Time out for a QProcess?
first of all, your connect() statement is incorrect. secondly your approach to the problem is incorrect.
Re: Time out for a QProcess?
Quote:
Originally Posted by
nish
first of all, your connect() statement is incorrect. secondly your approach to the problem is incorrect.
Thanks
Could you show my errors to me?
Re: Time out for a QProcess?
Quote:
Originally Posted by
nthung
Thanks
Could you show my errors to me?
Thanks
I think that when Tesst.exe take more than 1 second, althought that Tesst.exe still running, but Mother_Programwill pass proc.waitForFinished(1000);
Do you think that?
Thanks
Re: Time out for a QProcess?
Here is an incomplete list of things to consider (look for the comments):
Code:
#include <QtCore/QCoreApplication>
#include<QProcess>
#include<stdio.h>
class TIMEOUT{ // << needs to be derived from QObject to contain signals/slots
// << needs the Q_OBJECT macro for the same reason
public:
signals:
void timeout(); // << this should be a slot, not a signal
};
void TIMEOUT::timeout(){
//Help me code there. Thanks
// << You will need code to terminate the process
}
int main(int argc, char *argv[])
{
TIMEOUT timeout;
QObject::connect(&proc,
SIGNAL(timeout.
timeout()),
&a,
SLOT(quit
()));
// << QProcess has no signal called timeout.timeout() proc.execute("C:\\Tesst.exe"); // << this executes the program and waits for it to finish
printf("Hello"); // << Hi!
proc.waitForFinished(1000); // << pointless, the Tesst program has finished before it can get here
return a.exec();
}
To start and time out and terminate a sub process you will have to read:
The structure of your program will change quite a lot (or it won't compile)
Re: Time out for a QProcess?