title: How to make a MySQL query in Qt?
body: <p>I'm trying to create a simple app which allows user to enter a word and the app will output the definition. I have compiled words and definitions by making mysql database file. I thought using MySQL would be a faster way make my app. My database looks like this:</p>
  
  <pre><code>rowed      |  Column1(word)           | Column2(definition)
  1               DNA                      A double-stranded,helical...
  </code></pre>
  
  <p>The pseudocode for this program definitely should be like this:</p>
  
  <pre><code>if(lineEdit == wordInput)
  { 
      ui-&gt;label-&gt;setText("Display definition)
  } 
  </code></pre>
  
  <p>I just can't figure out how to do it. So far I have tried following code:</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QMessageBox&gt;
  #include &lt;QDebug&gt;
  #include &lt;QPalette&gt;
  
  #define Path_to_DB "/Users/makkhay/Desktop/nep_eng-2.sqlite"
  
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  
  {
      ui-&gt;setupUi(this);
         // Set background picture
         QPixmap bkgnd("/Users/makkhay/Desktop/background.jpg");
         bkgnd = bkgnd.scaled(this-&gt;size(), Qt::IgnoreAspectRatio);
         QPalette palette;
         palette.setBrush(QPalette::Background, bkgnd);
         this-&gt;setPalette(palette);
  
  
         myDB = QSqlDatabase::addDatabase("QSQLITE");
         myDB.setDatabaseName(Path_to_DB);
         QFileInfo checkFile(Path_to_DB);
  
         if(checkFile.isFile())
         {
             if(myDB.open())
             {
               ui-&gt;label-&gt;setText("The database is connected");
             }
  
         }else{
             ui-&gt;label-&gt;setText("No file found!");
         }
  
  
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
      myDB.close();
  }
  
  
  void MainWindow::on_pushButton_clicked()
  {
  //    QMessageBox::StandardButton reply= QMessageBox::question(this,
  //                                      "My Title", " Word not found, quit app?",
  //                                       QMessageBox::Yes | QMessageBox::No);
  
  
  //    if(reply == QMessageBox::Yes){
  
  //        QApplication::quit();
  //}
  
  
      if(!myDB.isOpen()){
          qDebug() &lt;&lt; " No connection to db";
          return;
      }
  
      QString wordInput, definition;
      wordInput = ui-&gt;lineEdit-&gt;text();
  
      QSqlQuery qry;
  
      qry.prepare("SELECT Column1,Column2 FROM Nepali WHERE Column1  = :input");
      qry.bindValue(":input",wordInput);
     // int fieldNo = query.record().indexof("Column1");
  
      if(qry.exec())
      {
          ui-&gt;debug-&gt;setText(" Checking output!");  // output is visible 
  
        while (qry.next())
         {
           ui-&gt;output-&gt;setText("Checing output!");  // output is not visible
  
  
          QString inputWord = qry.value(0).toString();
          QString wordDefinition = qry.value(1).toString();
          ui-&gt;output-&gt;setText(wordDefinition);
  
  
  
  
  
        }
      }
  
  }
  </code></pre>