-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconexion.cpp
executable file
·61 lines (54 loc) · 1.63 KB
/
conexion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "conexion.h"
#include "loggin.h"
#include <QDebug>
Conexion::Conexion(QObject *parent) : QObject(parent)
{
dbHost = "127.0.0.1"; // configDb.value("host").toString();
dbBase = "consulta"; // configDb.value("base").toString();
dbUsuario = "root"; // configDb.value("usuario").toString();
dbContrasena = "meganizado"; // configDb.value("contrasena").toString();
dbPuerto = "3306"; // configDb.value("puerto").toString();
qDebug() << dbHost;
qDebug() << dbBase;
qDebug() << dbUsuario;
qDebug() << dbContrasena;
qDebug() << dbPuerto;
}
bool Conexion::conectar()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","DB");
db.setHostName(dbHost);
db.setDatabaseName(dbBase);
db.setUserName(dbUsuario);
db.setPassword(dbContrasena);
db.setPort(dbPuerto.toInt());
if (!db.open()) {
mensaje.setText("Error de conexion");
mensaje.setInformativeText(db.lastError().text());
mensaje.exec();
Loggin *loggin = new Loggin();
loggin->exec();
conectar();
}
qDebug() << "conectando..";
return true;
}
QSqlDatabase Conexion::base()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","DB");
db.setHostName(dbHost);
db.setDatabaseName(dbBase);
db.setUserName(dbUsuario);
db.setPassword(dbContrasena);
db.setPort(dbPuerto.toInt());
if (!db.open()) {
mensaje.setText("Error de conexion");
mensaje.setInformativeText(db.lastError().text());
mensaje.exec();
Loggin *loggin = new Loggin();
loggin->exec();
conectar();
}
qDebug() << "conectando..";
return db;
}