Results 1 to 9 of 9

Thread: Strange behavior of return statement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Strange behavior of return statement

    d_stranz has it.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  2. #2
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange behavior of return statement

    Ok, sorry for posting only that part of a code which is executed during one pass through MyMethod which is making problems. Whole MyMethod logic is:

    Qt Code:
    1. void MyClass::MyMethod()
    2. {
    3. verifyPIN(); //user promted to enter PIN here
    4. if(verification was successfull)
    5. {
    6. do some atcions
    7. } else if(verification was unsuccessfull)
    8. {
    9. if(PIN was locked)
    10. {
    11. message->setWindowTitle("Error");
    12. message->setText("PIN was locked");
    13. message->setInformativeText("Do you wand to unblock PIN?");
    14. message->setIcon(QMessageBox::Critical);
    15. message->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    16. ret = message->exec();
    17.  
    18. if(ret == QMessageBox::Yes) unblockPIN();
    19. if(ret == QMessageBox::No)
    20. {
    21. suggestAction->setEnabled(true);
    22. solutions += "baz";
    23. this->suggestSolutions();
    24. }
    25. return;
    26. }
    27.  
    28. message->setWindowTitle("Title");
    29. message->setText("Wrong PIN");
    30. message->setIcon(QMessageBox::Critical);
    31. message->setStandardButtons(QMessageBox::Ok);
    32. message->exec();
    33. this->MyMethod();
    34. }
    35. treeClicked(navigator->currentItem());
    36. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Strange behavior of return statement

    Line 33 : MyMethod calls itself. This leads to a stack overflow.

  4. #4
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Strange behavior of return statement

    No, it does not. MyMethod calls itself only in case wrong PIN was entered and only limited times (3 times in most cases). After that, the pin is blocked and return statement is executed.

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

    Default Re: Strange behavior of return statement

    ... and then you get a cascade of returns, which is what you observe.
    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.


Similar Threads

  1. QSqlDatabase strange behavior
    By macav in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2011, 15:21
  2. strange behavior of paintEvent
    By hashb in forum Qt Programming
    Replies: 3
    Last Post: 30th August 2010, 07:48
  3. Strange behavior of QSqlTableModel
    By venomj in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 03:29
  4. Strange resize behavior
    By Lykurg in forum Newbie
    Replies: 3
    Last Post: 9th January 2007, 13:56
  5. scrollbars strange behavior
    By siniy in forum Qt Programming
    Replies: 6
    Last Post: 29th December 2006, 10:27

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.