Connect Qt to MariaDB Database

Viewed 58

I am going to connect my program, which is written in Qt, to my database which is defined in MariaDB DBMS (XAMPP Software Package). So as you can see in the figure below, I have to install a MySQL connector instead of a MariaDB connector (This is what my book, Hand on-GUI programming with C++ and Qt said). enter image description here

I installed the latest MySQL connector from its official website and I went running my project this is the error that I faced after running this code. enter image description here

The book said there is no need to worry just go copy the file "libmysql.dll" from the MySQL connector path to the execution path in Qt. The version I installed (MySQL Connector C++ 8.0), did not contain this file and I found a version (MySQL Connector C 6.1) that it does and I continued with the instructions of the book but the problem is not solved yet. I googled, checked StackOverflow questions, read articles, and search on youtube. Some of the solutions didn't work for me and others I didn't understand. Till now I just copied files such as "libmysql.dll", "qsqlmysql.dll", etc to many folders of Qt software path (and as u might guess nothing changed) and I also check the Qt website for this problem and I did not understand what should I do. I'll be very thankful to help me with this problem.

1 Answers

So I had the same problem earlier. (windows) enter image description here

then I found this link with debugged components. https://github.com/thecodemonkey86/qt_mysql_driver/releases and it worked.

enter image description here

I have the same server type as you, so it should work for you too. You have to put the appropriate files in the Qt folder. Only the current Qt version is important.

Put the files in these folders:

C:\Qt\6.3.1\mingw_64\plugins\sqldrivers

C:\Qt\6.3.1\mingw_64\lib

C:\Qt\6.3.1\mingw_64\bin

Make sure. That the database you set in Qt exists, otherwise you'll keep getting errors

Related