PDA

View Full Version : Stopping any further processing in nested if statements



thefatladysingsopera
8th November 2011, 12:13
I have the following function.


void haal::authenticate()
{
remoteDB();
QSqlQuery query("SELECT * FROM princess");
int ttwo = query.record().indexOf("two");
int tthree = query.record().indexOf("three");
int ffour = query.record().indexOf("four");
int ffive = query.record().indexOf("five");
int ssix = query.record().indexOf("six");
int sseven = query.record().indexOf("seven");
int eeight = query.record().indexOf("eight");
while (query.next()) {
QString aa = query.value(ttwo).toString();
QString bb = query.value(tthree).toString();
QString cc = query.value(ffour).toString();
QString dd = query.value(ffive).toString();
QString ee = query.value(ssix).toString();
QString ff = query.value(sseven).toString();
QString gg = query.value(eeight).toString();

if(aa != ui.validator->text())
{
QMessageBox msgBox;
msgBox.setText("That Key Is Not Valid.");
QPushButton *connectButton = msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
msgBox.exec();

if (msgBox.clickedButton() == connectButton)
{
//close();//exit the application
//qApp->exit(0);...stop further processing;exit the application
//how should it be done..
}
}
if(aa == ui.validator->text())
{
if (msgBox.clickedButton() == connectButton)
{
QMessageBox msgBox;
msgBox.setText("That Key Is Valid.");
}

QString kaad = getID();
QSqlQuery query;
query.prepare("INSERT INTO princess (one,two,three,four,five,six,seven) "
"VALUES (:one, :two, :three,:four,:five,:six,:seven)");
query.bindValue(":one", 78);
query.bindValue(":two", 7843251);
query.bindValue(":three",79);
query.bindValue(":four",80);
query.bindValue(":five",81);
query.bindValue(":six", 82);
query.bindValue(":seven",kaad);
query.exec();

}
}

}


I need to stop the processing here:


if (msgBox.clickedButton() == connectButton)
{
//close();//exit the application
//qApp->exit(0);...stop further processing;exit the application
//nothing to be executed below this line
}

stampede
8th November 2011, 12:53
break; to exit while loop or
continue; to move to next query result.

thefatladysingsopera
8th November 2011, 13:30
I have tried that but the processing continues.

stampede
8th November 2011, 14:09
Is the break; line executed , can you see the debug text ?

while (query.next()) {
....
if(aa != ui.validator->text())
{
....
if (msgBox.clickedButton() == connectButton)
{
qDebug() << "before break";
break;
}
}

everything below the "break" statement will not be executed, same as here:


#include <iostream>
int main(){
while( 1 ){
std::cout << "in while..."; // this will be visible only once
if( 1 ){
if( 1 ){
break; // while loop will end here
}
}
std::cout << "after break..."; // this will not be visible
}
return 0;
}