Results 1 to 6 of 6

Thread: Why my function is launched twice in my nextId function ?

  1. #1
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Why my function is launched twice in my nextId function ?

    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.
    Qt Code:
    1. int InstallDriverPage::nextId() const
    2. {
    3. QProcess *myProcess = new QProcess();
    4. if( myProcess->state() == QProcess::NotRunning ) // test if the process is already running or is starting.
    5. {
    6. myProcess->startDetached(QString("installdriver.exe"));
    7. }
    8. return ONmoveConverter::Page_ONmoveDetection;
    9. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,539
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why my function is launched twice in my nextId function ?

    Because when nextId() is called everytime it creates new QProcess.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why my function is launched twice in my nextId function ?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Why my function is launched twice in my nextId function ?

    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
    Last edited by Santosh Reddy; 22nd January 2013 at 21:24. Reason: updated contents
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why my function is launched twice in my nextId function ?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why my function is launched twice in my nextId function ?

    Thank you all for your support.

    B.R.

    Zidoune06

Similar Threads

  1. Replies: 11
    Last Post: 5th September 2012, 20:47
  2. Replies: 4
    Last Post: 2nd August 2012, 07:42
  3. Replies: 2
    Last Post: 13th September 2010, 20:03
  4. Replies: 3
    Last Post: 25th May 2010, 09:46
  5. Replies: 0
    Last Post: 10th March 2010, 08:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.