QProcess object not emitting finished(int) signal
Hello,
I have a weird trouble. I have created a QProcess object and started an external program. But... when program finishes, object is not emitting finished signal. How is this possible? What can I do to workaround this?
My code example:
Code:
launcher
::launcher(QWidget *parent, Qt
::WFlags flags
){
Sleep(3000);
program.start("/path/to/my/program.exe");
connect(&program, SIGNAL(finished(int)), this, SLOT(OnExit()));
}
void launcher::OnExit()
{
}
Re: QProcess object not emitting finished(int) signal
Your program doesn't even start. The QProcess object that controls it gets destroyed when you leave the constructor. Create it on heap instead.
Re: QProcess object not emitting finished(int) signal
this slot works, but your programm terminated immediately. create QProcess in a heap.
wysota, you was first :D
Re: QProcess object not emitting finished(int) signal
Well, actually my program does not end. I did not paste the whole constructor code :).
After connect.... line I have this:
while (true)
{
Sleep(1000)
}
So I stay in constructor and my program keeps running. It stays in constructor because I don't want it to open GUI. It's ugly I know but it works and runs hidden. With Sleep I prevent 100% CPU utilization.
Re: QProcess object not emitting finished(int) signal
create console app and run process.
Re: QProcess object not emitting finished(int) signal
I don't want to open any window, not even console. I want it to run as services do (completely hidden), but don't know how to program real service.
Now it seems like signal-slots communication does not work until execution leaves constructor??
Re: QProcess object not emitting finished(int) signal
if you need a service you can use QtService from Qt Solutions.
Re: QProcess object not emitting finished(int) signal
I never programmed a service and I want to be sure that I cannot achieve my goal any other way before diving into this.
I still do not understand why it does not work as it is now.
Re: QProcess object not emitting finished(int) signal
If I comment out while loop so that it opens GUI then object indeed emits signal. So it seems that with that loop I blocked processing of signals. Any other idea to create a "hidden" launcher without programming a service?
Re: QProcess object not emitting finished(int) signal
Hmmm, now I figured out something. I can leave constructor as in first post (without while loop), but just comment out following line in main.cpp:
//w.show();
and it works as intended (launches program, shows dialog box when program exits and stays completely hidden). Does this have any side effect?
Re: QProcess object not emitting finished(int) signal
what do you want to achive? do you use any GUI in your app or you need only start another process, so you don't need GUI?
Re: QProcess object not emitting finished(int) signal
Okay, I wil try to explain:
1. I DON'T want ANY window (NO GUI, no console either)
2. I just want to first run 2 other processes and then restart them if one of them dies/exits.
This is all I want. And it seems I can achieve that if i comment out w.show().
P.S.: I only had that QMessageBox because I tested behaviour. Application must stay completely silent normally.
Re: QProcess object not emitting finished(int) signal
there is some "magic" to hidding your app (i.e. that it don't appear in task bar), but for this "magic" you need to use platform dependent code.
so, I suggest to use QtService or take a look at QSystemTrayIcon
Re: QProcess object not emitting finished(int) signal
I think I "invented" such magic too :D