-1

I'm a newbie in using QT

Code :

void MainWindow::test()
{
  ui->label->setText("it worked !");
  proc->start("c:/windows/system32/calc.exe");
}

void MainWindow::on_pushButton_clicked()
{
   proc = new QProcess();
   connect(proc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(test()));
   proc->start("c:/windows/system32/notepad.exe");
}

So it starts notepad when I close it, calc is started but it keeps opening infinitely.

What's wrong in my code?

User
  • 11
  • 1

1 Answers1

1

Since you are not disconnecting the slot, the moment "calc.exe" exits it will be launched again.

I.e. when notepad.exe finishes, the signal triggers the test() slot which runs "calc.exe". When "calc.exec" finished, the very same series of events happens again.

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22
  • Thanks i added this disconnect(proc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(test())); to test function and it worked perfect. Just for curiousity am I using signal and slot in a wrong way ; is there any cleaner way to do it or is this fine? – User Dec 05 '16 at 20:06
  • Sounds ok. Alternatively you could check in `test()` which program has ended before launching calc.exe – Kevin Krammer Dec 06 '16 at 11:07