PDA

View Full Version : Why my function is launched twice in my nextId function ?



zidoune06
22nd January 2013, 17:17
Hello all,

I am working on a wizard.
I used to have a custom button to launch a process but it is not the solution my users want.
They want to have only one button, the "Next >" one.

So now, I would like to launch a process when my user selects the next button.
But when I put the code in the nextId() function, the process is launched twice.
I try to avoid that by testing the state of the process, in vain.


int InstallDriverPage::nextId() const
{
QProcess *myProcess = new QProcess();
if( myProcess->state() == QProcess::NotRunning ) // test if the process is already running or is starting.
{
myProcess->startDetached(QString("installdriver.exe"));
}
return ONmoveConverter::Page_ONmoveDetection;
}


FYI : When I press the Next button on page Z, I go to the next page Z+1, not Z+2.

Does someone know how I can do that?
Thank you in advance for your support.

Zidoune06

Lesiok
22nd January 2013, 17:25
Because when nextId() is called everytime it creates new QProcess.

wysota
22nd January 2013, 18:21
See QWizardPage::initializePage().

Santosh Reddy
22nd January 2013, 21:16
Const member functions should be implemented in such a way that any number calls to the function will not change the state of the object and related functionality. Now here even though the compiler allows you to create persistent objects (in a const member function), it is in fact a bad practice to to do and your problem is a good example of what happens.

Edited: Removed the example code

wysota
22nd January 2013, 21:18
I would create and run the process in initializePage() of the next page. However tasks doing persistent changes should be launched only during the last stage of the wizard (e.g. in initializePage() of the final page with back button disabled). Otherwise by going back one should revert all the changes made to the system.

zidoune06
28th March 2013, 18:03
Thank you all for your support.

B.R.

Zidoune06