Global unique database connection
this looks like the way qt should work, and doing otherwise (creating and destroyng continuously the connection) gives a lot of warnings at runtime
This commit is contained in:
parent
aefe4ba9cd
commit
dc5387b63c
|
@ -5,7 +5,6 @@ EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(n
|
|||
ui->setupUi(this);
|
||||
|
||||
if (!db.open()) {
|
||||
// QMessageBox::critical(this, "Nicolodi", "Problemi con la connessione al db");
|
||||
showError(db.lastError());
|
||||
this->doNotShow = true;
|
||||
return;
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
#include "ui_Pin.h"
|
||||
#include "EditWindow.h"
|
||||
|
||||
Pin::Pin(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Pin)
|
||||
{
|
||||
Pin::Pin(QWidget *parent) : QDialog(parent), ui(new Ui::Pin) {
|
||||
ui->setupUi(this);
|
||||
|
||||
// Imposta la dialog come non ingrandibile/riducibile
|
||||
|
@ -30,8 +27,6 @@ void Pin::on_pushButtonOk_clicked()
|
|||
bool questionarioAbilitato;
|
||||
QString pin = ui->lineEditPin->text();
|
||||
|
||||
connectDatabase();
|
||||
|
||||
if (db.open()) {
|
||||
query = QSqlQuery(db);
|
||||
query.prepare("SELECT id, abilitaQuestionario FROM socio WHERE pin = :pin");
|
||||
|
@ -60,7 +55,7 @@ void Pin::on_pushButtonOk_clicked()
|
|||
// sono risorse preziose che si devono aprire, usare per il minor
|
||||
// tempo possibile e quindi chiudere
|
||||
query.clear();
|
||||
db.close();
|
||||
//db.close();
|
||||
} else {
|
||||
QMessageBox::critical(this, "Nicolodi", "Impossibile connettersi al database, verificare impostazioni.");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
// MainWindow w;
|
||||
|
||||
connectDatabase();
|
||||
|
||||
Pin w;
|
||||
w.show();
|
||||
|
||||
|
|
Loading…
Reference in New Issue