Important: Please read the Qt Code of Conduct -

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.


    #include "principalclass.h"
    #include "ui_principalclass.h"
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QMessageBox>
    PrincipalClass::PrincipalClass(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::PrincipalClass)
        QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
                                  "driver was not found.\n"+db.lastError().text());
                                  "error opening database.\n"+db.lastError().text());
                                 "Todo bien");
        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 see QSqlDatabase 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 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 this



    and there was no result, I get this.

  • Lifetime Qt Champion

    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.

  • Lifetime Qt Champion

    @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.

  • Lifetime Qt Champion

    @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:


    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.

Log in to reply