Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Displaying database values with radio button selection?

$
0
0
Hi, 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 : 1) QMainWindow 2) QSqlTableModel 3) QTableWidget. But which one satisfies my requirement? I am not able to implement it, please guide me. Thanks in advance. I have implemented upto this in my sourcefile main.cpp: #include <QtGui/QApplication> #include <QtSql> #include <QTableWidget> #include <QMessageBox> #include "mainwindow.h" #include <QRadioButton> #include <QVBoxLayout> #include <QGroupBox>   int main(int argc, char *argv[]) {     QApplication a(argc, argv);       QTableWidget* table = new QTableWidget();     table->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->setColumnCount(query.record().count());         table->setRowCount(query.size());           int index=0;         while (query.next())         {               table->setItem(index,0,new QTableWidgetItem(query.value(0).toString()));             table->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->setWindowTitle(QString::fromUtf8("QGroupBox"));         window->resize(400, 400);         QGroupBox *groupBox = new QGroupBox("Radio Buttons");         QRadioButton *radio1 = new QRadioButton("Radio button 1");         radio1->setChecked(true);         QVBoxLayout *vbox = new QVBoxLayout;         vbox->addWidget(radio1);         groupBox->setLayout(vbox);         window->setCentralWidget(groupBox);         window->show();           table->show();                                          //MainWindow w; w.show();           return a.exec(); }

Viewing all articles
Browse latest Browse all 18427

Latest Images

Trending Articles



Latest Images