title: Displaying database values with radio button selection in Qt?
body: <p>I want to show some database row values with radio button selection in Qt GUI. How this can be accomplished?. This could be done using foreach loop I guess. I have studied a bit about the following classes :</p>
  
  <p>1) QMainWindow
  2) QSqlTableModel
  3) QTableWidget.</p>
  
  <p>But which one satisfies my requirement? I am not able to implement it, please guide me. Thanks in advance.</p>
  
  <p>I have implemented upto this in my source file-</p>
  
  <p><strong>main.cpp</strong>:</p>
  
  <pre><code>#include &lt;QtGui/QApplication&gt;
  #include &lt;QtSql&gt;
  #include &lt;QTableWidget&gt;
  #include &lt;QMessageBox&gt;
  #include "mainwindow.h"
  #include &lt;QRadioButton&gt;
  #include &lt;QVBoxLayout&gt;
  #include &lt;QGroupBox&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      QTableWidget* table = new QTableWidget();
      table-&gt;setWindowTitle("Connect to Mysql Database Example");
  
          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("localhost");
          db.setDatabaseName("guests");
          db.setUserName("sri");
          db.setPassword("******");
          if (!db.open())
          {
            QMessageBox::critical(0, QObject::tr("Database Error"),
            db.lastError().text());
          }
  
          QSqlQuery query("SELECT * FROM new_members");
  
          table-&gt;setColumnCount(query.record().count());
          table-&gt;setRowCount(query.size());
  
          int index=0;
          while (query.next())
          {
  
              table-&gt;setItem(index,0,new QTableWidgetItem(query.value(0).toString()));
              table-&gt;setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
  
              index++;
  
          }
  
  // This is sample radiobutton from QGroupBox class. Like this I need to implement the values from DB in with radio button selections for each value
  
          QMainWindow *window = new QMainWindow();
          window-&gt;setWindowTitle(QString::fromUtf8("QGroupBox"));
          window-&gt;resize(400, 400);
          QGroupBox *groupBox = new QGroupBox("Radio Buttons");
          QRadioButton *radio1 = new QRadioButton("Radio button 1");
          radio1-&gt;setChecked(true);
          QVBoxLayout *vbox = new QVBoxLayout;
          vbox-&gt;addWidget(radio1);
          groupBox-&gt;setLayout(vbox);
          window-&gt;setCentralWidget(groupBox);
          window-&gt;show();
  
          table-&gt;show();
                                           //MainWindow w; w.show();
  
          return a.exec();
  }
  </code></pre>