Results 1 to 4 of 4

Thread: Stopping any further processing in nested if statements

  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Stopping any further processing in nested if statements

    I have the following function.

    Qt Code:
    1. void haal::authenticate()
    2. {
    3. remoteDB();
    4. QSqlQuery query("SELECT * FROM princess");
    5. int ttwo = query.record().indexOf("two");
    6. int tthree = query.record().indexOf("three");
    7. int ffour = query.record().indexOf("four");
    8. int ffive = query.record().indexOf("five");
    9. int ssix = query.record().indexOf("six");
    10. int sseven = query.record().indexOf("seven");
    11. int eeight = query.record().indexOf("eight");
    12. while (query.next()) {
    13. QString aa = query.value(ttwo).toString();
    14. QString bb = query.value(tthree).toString();
    15. QString cc = query.value(ffour).toString();
    16. QString dd = query.value(ffive).toString();
    17. QString ee = query.value(ssix).toString();
    18. QString ff = query.value(sseven).toString();
    19. QString gg = query.value(eeight).toString();
    20.  
    21. if(aa != ui.validator->text())
    22. {
    23. QMessageBox msgBox;
    24. msgBox.setText("That Key Is Not Valid.");
    25. QPushButton *connectButton = msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
    26. msgBox.exec();
    27.  
    28. if (msgBox.clickedButton() == connectButton)
    29. {
    30. //close();//exit the application
    31. //qApp->exit(0);...stop further processing;exit the application
    32. //how should it be done..
    33. }
    34. }
    35. if(aa == ui.validator->text())
    36. {
    37. if (msgBox.clickedButton() == connectButton)
    38. {
    39. QMessageBox msgBox;
    40. msgBox.setText("That Key Is Valid.");
    41. }
    42.  
    43. QString kaad = getID();
    44. QSqlQuery query;
    45. query.prepare("INSERT INTO princess (one,two,three,four,five,six,seven) "
    46. "VALUES (:one, :two, :three,:four,:five,:six,:seven)");
    47. query.bindValue(":one", 78);
    48. query.bindValue(":two", 7843251);
    49. query.bindValue(":three",79);
    50. query.bindValue(":four",80);
    51. query.bindValue(":five",81);
    52. query.bindValue(":six", 82);
    53. query.bindValue(":seven",kaad);
    54. query.exec();
    55.  
    56. }
    57. }
    58.  
    59. }
    To copy to clipboard, switch view to plain text mode 

    I need to stop the processing here:

    Qt Code:
    1. if (msgBox.clickedButton() == connectButton)
    2. {
    3. //close();//exit the application
    4. //qApp->exit(0);...stop further processing;exit the application
    5. //nothing to be executed below this line
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Stopping any further processing in nested if statements

    Qt Code:
    1. break;
    To copy to clipboard, switch view to plain text mode 
    to exit while loop or
    Qt Code:
    1. continue;
    To copy to clipboard, switch view to plain text mode 
    to move to next query result.

  3. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Stopping any further processing in nested if statements

    I have tried that but the processing continues.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Stopping any further processing in nested if statements

    Is the break; line executed , can you see the debug text ?
    Qt Code:
    1. while (query.next()) {
    2. ....
    3. if(aa != ui.validator->text())
    4. {
    5. ....
    6. if (msgBox.clickedButton() == connectButton)
    7. {
    8. qDebug() << "before break";
    9. break;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    everything below the "break" statement will not be executed, same as here:
    Qt Code:
    1. #include <iostream>
    2. int main(){
    3. while( 1 ){
    4. std::cout << "in while..."; // this will be visible only once
    5. if( 1 ){
    6. if( 1 ){
    7. break; // while loop will end here
    8. }
    9. }
    10. std::cout << "after break..."; // this will not be visible
    11. }
    12. return 0;
    13. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to stampede for this useful post:

    thefatladysingsopera (9th November 2011)

Similar Threads

  1. QSqlQuery prepared statements proper usage
    By psih128 in forum Qt Programming
    Replies: 5
    Last Post: 11th April 2011, 23:10
  2. how to avoid switch statements in item delegates
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 9th March 2011, 21:11
  3. QtSql: Maximum number of PREPARE statements
    By kayssun in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2010, 09:51
  4. QtSql: execBatch() with SELECT statements
    By herrmarder in forum Qt Programming
    Replies: 2
    Last Post: 28th January 2010, 13:43
  5. reading fprintf statements from console in qt
    By KrishnaKishan in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2007, 10:00

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.