2.2.Qt ga Accesni bog’lash va Xozmak loyiha dasturini yaratish
Biz birinchi navbatda Qt creator ni ishga tushirib dastur tuzishga tayyor holga kelgan so’ng dastur tuzishni boshlaymiz. Ishchi maydonga Push Button tugmadan 5ta quyib text xususiyatdan tugmani nomlab chiqamz dastur natijasni tableViewchiqaradigan qilamz.Bu dastrur kodi:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QString"
#include
#include
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db;
QSqlQueryModel *m=new QSqlQueryModel();
db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=Xozmak.mdb");
db.open();
if(!db.open())
{
QMessageBox::critical(this,tr("Ошибка"),db.lastError().text());
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
model = new QSqlTableModel(this);
model->setTable("Bulimlar");
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
}
void MainWindow::on_pushButton_5_clicked()
{
Model = new QSqlTableModel(this);
model->setTable("Mahsulotlar");
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
}
void MainWindow::on_pushButton_4_clicked()
{
model = new QSqlTableModel(this);
model->setTable("Mijozlar");
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
}
void MainWindow::on_pushButton_2_clicked()
{
model = new QSqlTableModel(this);
model->setTable("Stroy(DukonNomlari)");
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
}
void MainWindow::on_pushButton_3_clicked()
{
model = new QSqlTableModel(this);
model->setTable("Xodimlar");
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
}
Shu tarzda har bir tugmaning clicked xususiyatidan foydalanib dasturkodini kiritib chiqamz.
Tugmalar joylashtirilib dasturni dezayn qismiga o’tamiz orqa fon bilan ishlash StyleSheet bo’limidan Background color bo’limini tanlab tugmalarga rang berib chiqamz.
Dasturimizni dezayn qismi ham kod qismi ham tayyor bo’ldi.dasturni ishlatib ko’ramz.
Ko’rib turganingizdek dasturimiz ishlaybadi.Biz dasturimizda Bulimlar tugmasini bosamiz va Xozmak dukonida bulimlar nomlarini va shu bulim raxbari va ism famelyasini kurishimiz mumkin.
Keying biz Story(DukonNomlari) tumasini bosamiz va bizga xozmak dukonlari nomlari va aniq manzillarini kurishimiz mumkin.
Shu tarzda tugmalarni bosak ma’lumotlar chiqib keladi.Keyingi ma’lumot xodimlar bulimiga kiramiz bu bulimda biz ishchi xodimlarni kurishimiz mumkin ularning fameliya ismi va aniq manzillari keltirilga shu bilan birgalikda hodim telefon raqami va uning elektron pochta manzilini kurishimiz mumkin.
Biz kuradigan hozirgi bulimimiz mijozlar bulimi bu bulimda biz mijoz haqida malumot olishimiz mumkin . Bizga mijoz ism famelyasi, uning telefon raqami va uning yashaydigan viloyatini kurishimiz mumkin .
Kiyingi va nihoyat siz bilan oxirgi bulimni kurishimiz mumkin bu bulimda biz sizga yani foydalanuvchiga kurinadigan qismi mahsulotimizning idsi, nomi va uning qaysi bulimga tegishli ekanligi kurinib turadi.
Har bir tugmani bosganimzda tugmadagi nom orqali uning xususiyatlari tableView widgetga chiqadi. Bu bulimlarni kurib turganizdek hamma bulimlar bilan tanishib chiqdik va shularni hammasini ishlashini va ishlatishni urganib chiqdik.
Do'stlaringiz bilan baham: |