I want whenever if (while ()) comes it will print Checking condition for If Statement and whenever while (if ()) comes it will print Checking condition for While Statement. I tried this code:

if(cursor.block().text().contains("while",Qt::Case Insensitive)&& cursor.block().text().contains("(",Qt::CaseInsensi tive))
{
ui->label->setText("Checking condition for While Statement");

}
if(cursor.block().text().contains("if",Qt::CaseIns ensitive)&&cursor.block().text().contains("(",Qt:: CaseInsensitive))
{
ui->label->setText("Checking condition for If Statement");
}

when i entered only if () and only while () then it gives Checking condition for If Statement and Checking condition for While Statement respectively. But when i entered if (while ()) and while (if ()), it gives Checking condition for If Statement in both the cases.