samedi 30 septembre 2017

Both if else statements executing togetther qt c++

I have written a function to search words in qtable widget(which has 10 rows) and display the relevant word on the the 1st row if the word in the table widget.

But unforutnately when I enter a word in the tablewidget and click the button the message box in the else statement executes 1st and then the word is shown on the 1st row!

void MainWindow::on_pushButton_clicked()
{

  QString Line = ui->lineEdit->text();
  for(int i = 0; i < 10; ++i)
  {
      if(ui->tableWidget->item(i, 0)->text() == Line)
      {

          ui->tableWidget->clear();
          ui->tableWidget->setItem(0,0,new QTableWidgetItem(Line));
          break;
      }
      else{

          QMessageBox::information(this,"Word not found","The word you are searching is not in the list");
          break;

      }
  }

How can I correct this?

Aucun commentaire:

Enregistrer un commentaire