#include <QDate>#include <QtSql>#include "mainwindow.h"#include "ui_mainwindow.h"void DBaddData(){ QSqlDatabase myBase=QSqlDatabase::addDatabase("QSQLITE"); myBase.setDatabaseName("allDataODKO"); myBase.open(); QSqlQuery myquery; myquery.exec("create table pDB(id int primary key,PCA int)"); myquery.exec("insert into pDB(id,PCA) values(12,212)");}MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); //---------- QDate dateNow=QDate::currentDate(); ui->lineEdit_20->setText(dateNow.toString("dd.MM.yyyy")); //----------}MainWindow::~MainWindow(){ delete ui;}void MainWindow::on_pushButton_2_clicked(){ //это кнопка выхода из программы close();}void MainWindow::on_pushButton_clicked(){ //функция нажатия на кнопку внесения DBaddData();}
void DBTestConn(){ QSqlQuery myquery; QSqlDatabase myBase=QSqlDatabase::addDatabase("QSQLITE","myCONNECTION"); myBase.setDatabaseName("D:/allDataODKO.db"); myBase.open(); myquery.exec("create table pDB (id integer primary key,PCA integer)"); myquery.exec("insert into pDB values(1,2)"); myBase.close(); myBase.removeDatabase("myCONNECTION");}
C++ (Qt)void DBCreate(){ QSqlDatabase myBase=QSqlDatabase::addDatabase("QSQLITE"); myBase.setDatabaseName("D:/allDataODKO.db"); if (!myBase.open()) { qDebug () << myBase.lastError ().text (); } else { QSqlQuery myquery; myquery.exec("create table pDB (id integer primary key,PCA integer)"); const boo result = myquery.exec("insert into pDB values(1,2)"); if (!result) { qDebug () << myquery.lastError ().text (); } } myBase.close ()}
void DBTestConn(){ QSqlDatabase myBase=QSqlDatabase::addDatabase("QSQLITE","myCONNECTION"); myBase.setDatabaseName("allDataODKO.db"); myBase.open(); QSqlQuery myquery(myBase); myquery.exec("create table pDB (id int,PCA int)"); myquery.exec("insert into pDB values(1,2)"); myBase.close(); myBase.removeDatabase("myCONNECTION");}
QSqlQuery myquery(myBase);
void DBTestConn(){ QSqlDatabase myBase=QSqlDatabase::addDatabase("QSQLITE","myCONNECTION"); myBase.setDatabaseName("allDataODKO.db"); myBase.open(); QSqlQuery myquery(myBase); myquery.exec("create table pDB (id int,PCA int)"); myquery.exec("insert into pDB values(1,2)"); myBase.close(); } QSqlDatabase::removeDatabase("myCONNECTION");