Unsolved error connecting to Mysql
-
good afternoon.
I have a question regarding database, I have a database made in mysql, and when I want to connect from qt, I get an error message, that the controller was not found, and when I see the message it comes out that they are only available the sqlite, postgre and obdc drivers, maybe in the version of qt that I am using that driver is no longer available, I am using version 5.13.1 of qt, I would appreciate your comments, I leave the code I made to connect to the base of data, I also leave a screenshot of the error message.codigo:
#include "principalclass.h" #include "ui_principalclass.h" #include <QSqlDatabase> #include <QSqlError> #include <QMessageBox> PrincipalClass::PrincipalClass(QWidget *parent) : QMainWindow(parent) , ui(new Ui::PrincipalClass) { ui->setupUi(this); QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL"); if(!db.isDriverAvailable("QMYSQL")) { QMessageBox::critical(this,qApp->applicationName(), "driver was not found.\n"+db.lastError().text()); return; } db.setPort(3306); db.setHostName("localhost"); db.setDatabaseName("ejemplo"); db.setUserName("root"); db.setPassword("2311046"); if(!db.open()) { QMessageBox::critical(this,qApp->applicationName(), "error opening database.\n"+db.lastError().text()); return; } QMessageBox::information(this,qApp->applicationName(), "Todo bien"); } PrincipalClass::~PrincipalClass() { delete ui; }
-
@lincoln
You are not configured yet to use MySQL. This comes up so often here I think there may be post, search this forum or Google for the message you seeQSqlDatabase QMYSQL driver not loaded
, pick a recent-ish answer, there are several. If you have to build it yourself, and you're Windows, the main stickied thread at https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt may be relevant, but I think you can get it pre-compiled for Windows from somewhere. -
Well I take it back, my question would be, how to build the mysql driver in qt 5.13.1, I already tried to do it with the official QT documentation but I didn't get it.
I did thisand there was no result, I get this.
-
Move the mysql libs to a path without spaces and try again. Or properly quote your paths or use MYSQL_INCDIR/MYSQL_LIBDIR as stated in the documentation
-
Well friends, I tried everything and there is no result, thanks anyway.
-
@lincoln said in error connecting to Mysql:
Well friends, I tried everything and there is no result, thanks anyway.
What did you do? You will at least get another error message than the one above.
-
I tried an ODBC connection but I also got an error, so I think I'll leave it there, I will try PostGresql.
-
@lincoln said in error connecting to Mysql:
I tried an ODBC connection
So you never tested our suggestions... good to know :(
-
@christian-ehrlicher said in error connecting to Mysql:
MYSQL_INCDIR/MYSQL_LIBDIR
I did what they told me, but I got more errors than in the beginning, I don't even compile when I switch to MYSQL_INCDIR / MYSQL_LIBDIR, as you said, so I left it like that, I have to move forward with this since it is a job for the university, I thank you for your comments.