Deploy qt desktop app 'Driver not loaded'
-
Change my odbc conection
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("Driver={MySQL ODBC 8.0 ANSI Driver};Server=localhost;DATABASE=tunqui_restaurante;"); db.setUserName("root"); db.setPassword("");
and my query
//if (query.size()>0) comment this line { while(query.next()) { us.set_ID_usuario(query.value("ID_usuario").toInt()); us.set_nombre(query.value("nombre").toString()); us.set_apellido(query.value("apellido").toString()); us.set_dni(query.value("dni").toString()); us.set_telefono(query.value("telefono").toString()); us.set_correo(query.value("correo").toString()); us.set_cargo(query.value("cargo").toInt()); us.set_direccion(query.value("direccion").toString()); } //}
ODBC conection work fine and I can log in my app (error code fixed)
But when I deploy with windeployqt I had the same problem with QMYSQL
windeployqt command : windeployqt restaurante_tunqui.exe
-
I found the solution:
#include "controlador.h" #include "qmessagebox.h" controlador::controlador() { } static QSqlDatabase con=conexion().conecta();
to
usuario controlador::logear(acceso ac) { usuario us= usuario(); QSqlDatabase con=conexion().conecta(); QSqlQuery query(con);
#include "vistas/login.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication::libraryPaths(); QApplication a(argc, argv); login w; w.show(); return a.exec(); }
https://forum.qt.io/topic/66480/deploy-on-windows/14
I think because static db conection, windeployqt work fine
-
There's really no need for any static (nor class variable) QDatabase object. QDatabase already provide all methods needed to create and retrieve database connection when needed.