I can compile my program but when i press push button doesn't happen and i don't know why?
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "osm_sqlite.h"
namespace Ui {
class MainWindow;
}
class Osm_Sqlite;
Q_OBJECT
private:
Osm_Sqlite osmdb;
public:
~MainWindow();
protected:
private:
Ui::MainWindow *ui;
private slots:
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "osm_sqlite.h"
namespace Ui {
class MainWindow;
}
class Osm_Sqlite;
class MainWindow : public QMainWindow {
Q_OBJECT
private:
Osm_Sqlite osmdb;
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
private slots:
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "osm_sqlite.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
osmdb=Osm_Sqlite("d:\\db1");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_clicked()
{
osmdb.Create_clean_database();
//this->osmdb.Create_clean_database();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "osm_sqlite.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
osmdb=Osm_Sqlite("d:\\db1");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_clicked()
{
osmdb.Create_clean_database();
//this->osmdb.Create_clean_database();
}
To copy to clipboard, switch view to plain text mode
my class:
#ifndef OSM_SQLITE_H
#define OSM_SQLITE_H
#include <QtSql>
#include <QSqlQuery>
class Osm_Sqlite
{
private:
public:
Osm_Sqlite();
~Osm_Sqlite();
bool Create_clean_database();
};
#endif // OSM_SQLITE_H
#ifndef OSM_SQLITE_H
#define OSM_SQLITE_H
#include <QtSql>
#include <QSqlQuery>
class Osm_Sqlite
{
private:
QSqlDatabase db;//=QSqlDatabase::addDatabase("QSQLITE");
QSqlQuery query;
public:
Osm_Sqlite();
Osm_Sqlite(QString patch_to_db);
~Osm_Sqlite();
bool Create_clean_database();
};
#endif // OSM_SQLITE_H
To copy to clipboard, switch view to plain text mode
#include "osm_sqlite.h"
//konstruktory
Osm_Sqlite::Osm_Sqlite()
{
}
Osm_Sqlite
::Osm_Sqlite(QString patch_to_db
){
this->db.setDatabaseName(patch_to_db);
bool ok = db.open();
qDebug() << ok;
if (!ok)
{
qDebug() << "Błąd: nie można się połączyć z bazą!";
if(this->db.lastError().isValid())
{
qDebug() << this->db.lastError();
}
}
else
{
qDebug() << "Nawiązano połączenie z bazą danych.";
}
//spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane. Po prostu zleci ich wykonanie i będzie dalej kontynuować swoje operacje. Może to znacząco zwiększyć szybkość SQLite.
//query.exec("PRAGMA synchronous=OFF");
db.close();
}
//destruktor
Osm_Sqlite::~Osm_Sqlite()
{
this->db.close();
delete &db;
}
// usuwa wszystkie wpiosy z bazy danych i tworzy czystÄ… strukture nowej bazy danych;
bool Osm_Sqlite::Create_clean_database()
{
bool ok = db.open();
// query.exec("select * from tb11");
//
// while (query.next())
// {
// QString name = query.value(0).toString();
//
// qDebug() << name;
// }
//usuniecie tabel
query.exec("drop table Pacjent");
query.exec("drop table Dysk");
query.exec("drop table PlikDicom");
query.exec("CREATE TABLE Pacjent(id_p INTEGER PRIMARY KEY,Imie VARCHAR(20),Nazwisko VARCHAR(20),Pesel VARCHAR(11),Plec VARCHAR(1));");
query.exec("CREATE TABLE Dysk(id_d INTEGER PRIMARY KEY,NazwaPlyty VARCHAR(20),DataArch VARCHAR(8),id_p INTEGER;");
query.exec("CREATE TABLE PlikDicom(id_pd INTEGER PRIMARY KEY,NazwaPliku VARCHAR(20),DataUtworzenia VARCHAR(8),SeriesDescript VARCHAR(20),Modality VARCHAR(10));");
query.exec("CREATE INDEX name_ind on Pacjent(Nazwisko);");
query.exec("CREATE INDEX pesel_ind on Pacjent(Pesel);");
query.exec("CREATE INDEX dane on Pacjent(Pesel,Nazwisko);");
query.exec("CREATE INDEX nazwaplyty_ind on Dysk(NazwaPlyty);");
query.exec("CREATE INDEX dataarch_ind on Dysk(DataArch);");
//spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane
//query.exec("PRAGMA synchronous=OFF");
//wyswietla informacje jesli nastapily jakies bledy
if(db.lastError().isValid())
{
qDebug() << db.lastError();
return false;
}
db.close();
return true;
}
#include "osm_sqlite.h"
//konstruktory
Osm_Sqlite::Osm_Sqlite()
{
}
Osm_Sqlite::Osm_Sqlite(QString patch_to_db)
{
this->db=QSqlDatabase::addDatabase("QSQLITE");
this->db.setDatabaseName(patch_to_db);
bool ok = db.open();
qDebug() << ok;
if (!ok)
{
qDebug() << "Błąd: nie można się połączyć z bazą!";
if(this->db.lastError().isValid())
{
qDebug() << this->db.lastError();
}
}
else
{
qDebug() << "Nawiązano połączenie z bazą danych.";
}
this->query=QSqlQuery::QSqlQuery(this->db);
//spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane. Po prostu zleci ich wykonanie i będzie dalej kontynuować swoje operacje. Może to znacząco zwiększyć szybkość SQLite.
//query.exec("PRAGMA synchronous=OFF");
db.close();
}
//destruktor
Osm_Sqlite::~Osm_Sqlite()
{
this->db.close();
delete &db;
}
// usuwa wszystkie wpiosy z bazy danych i tworzy czystÄ… strukture nowej bazy danych;
bool Osm_Sqlite::Create_clean_database()
{
bool ok = db.open();
QSqlDatabase::database().transaction();
// query.exec("select * from tb11");
//
// while (query.next())
// {
// QString name = query.value(0).toString();
//
// qDebug() << name;
// }
//usuniecie tabel
query.exec("drop table Pacjent");
query.exec("drop table Dysk");
query.exec("drop table PlikDicom");
query.exec("CREATE TABLE Pacjent(id_p INTEGER PRIMARY KEY,Imie VARCHAR(20),Nazwisko VARCHAR(20),Pesel VARCHAR(11),Plec VARCHAR(1));");
query.exec("CREATE TABLE Dysk(id_d INTEGER PRIMARY KEY,NazwaPlyty VARCHAR(20),DataArch VARCHAR(8),id_p INTEGER;");
query.exec("CREATE TABLE PlikDicom(id_pd INTEGER PRIMARY KEY,NazwaPliku VARCHAR(20),DataUtworzenia VARCHAR(8),SeriesDescript VARCHAR(20),Modality VARCHAR(10));");
query.exec("CREATE INDEX name_ind on Pacjent(Nazwisko);");
query.exec("CREATE INDEX pesel_ind on Pacjent(Pesel);");
query.exec("CREATE INDEX dane on Pacjent(Pesel,Nazwisko);");
query.exec("CREATE INDEX nazwaplyty_ind on Dysk(NazwaPlyty);");
query.exec("CREATE INDEX dataarch_ind on Dysk(DataArch);");
//spowoduje że SQLite nie będzie czekało aż operacje na dysku zostaną wykonane
//query.exec("PRAGMA synchronous=OFF");
QSqlDatabase::database().commit();
//wyswietla informacje jesli nastapily jakies bledy
if(db.lastError().isValid())
{
qDebug() << db.lastError();
return false;
}
db.close();
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks