#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
mydb.setDatabaseName("C:/sqlite/etudiant.sqlite");
if(!mydb.open())
{
qDebug() << "Fail";
}
else
{
qDebug() << "connected";
req->prepare("SELECT name FROM note");
req->exec();
modal->setQuery(*req);
ui->comboBox->setModel(modal);
}
}
Widget::~Widget()
{
delete ui;
}
void Widget
::on_comboBox_currentIndexChanged(const QString &arg1
) {
QString name
= ui
->comboBox
->currentText
();
qry.prepare("SELECT * FROM note WHERE name = '"+name+"'");
if(qry.exec())
{
while (qry.next()) {
ui->lineEdit->setText(qry.value(1).toString());
ui->lineEdit_2->setText(qry.value(2).toString());
}
}
}
CREATE TABLE note(id INTEGER PRIMARY KEY, name VARCHAR(25), surname VARCHAR(25));
INSERT INTO note VALUES(1, 'Jhon', 'Samuel');INSERT INTO note VALUES(2, 'Eddy', 'Ron');INSERT INTO note VALUES(3, 'Jhon', 'Mark');
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
mydb = QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("C:/sqlite/etudiant.sqlite");
if(!mydb.open())
{
qDebug() << "Fail";
}
else
{
QSqlQueryModel *modal = new QSqlQueryModel();
qDebug() << "connected";
QSqlQuery *req = new QSqlQuery(mydb);
req->prepare("SELECT name FROM note");
req->exec();
modal->setQuery(*req);
ui->comboBox->setModel(modal);
}
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_comboBox_currentIndexChanged(const QString &arg1)
{
QString name = ui->comboBox->currentText();
QSqlQuery qry;
qry.prepare("SELECT * FROM note WHERE name = '"+name+"'");
if(qry.exec())
{
while (qry.next()) {
ui->lineEdit->setText(qry.value(1).toString());
ui->lineEdit_2->setText(qry.value(2).toString());
}
}
}
CREATE TABLE note(id INTEGER PRIMARY KEY, name VARCHAR(25), surname VARCHAR(25));
INSERT INTO note VALUES(1, 'Jhon', 'Samuel');INSERT INTO note VALUES(2, 'Eddy', 'Ron');INSERT INTO note VALUES(3, 'Jhon', 'Mark');
To copy to clipboard, switch view to plain text mode
Bookmarks