QMYSQL driver not Loaded Qtcreator

Asked

Viewed 461 times

4

I am trying to connect to the database with Qtcreator as follows:

this->db = QSqlDatabase::addDatabase("QMYSQL");
this->db.setHostName("localhost");
this->db.setDatabaseName("Pessoa");
this->db.setUserName("root");
this->db.setPassword("");
if(this->db.open();

But the application returns:

Qsqldatabase: QMYSQL driver not Loaded Qsqldatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

I already installed the qt-mysql and no . pro QT += sql. What I must do beyond that to have connection?

Obs.:

Version of Qt = 5.2.1

OS = GNU/Linux Fedora

  • Did you check whether the qt-mysql accessible in PATH? If you installed while Qt was open, you need to restart Qt (at least on Windows).

  • I added the path to the environment variable, but still keeps returning the same error.

2 answers

1

I decided to install the package

Qt5-qtbase-mysql

and copying the file

/usr/lib64/Qt5/plugins/sqldrivers/libqsqlmysql.so

replacing the file located in

/opt/Qt5.2.1/5.2.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so.

0

Make sure the mysql library is in a location accessible to Qt (/usr/lib/, /usr/lib/i386-linux-gnu or something like).

As you said you have already installed mysql, you should find the following library:

libmysqlclient_r.so or libmysqlclient.so or libmysqlclient_r.so.16

This is the library that Qt needs to run the mysql driver, as can be seen in . pro which compiles the Qt mysql driver, in this snippet:

unix {
    isEmpty(QT_LFLAGS_MYSQL) {
        !contains(LIBS, .*mysqlclient.*):!contains(LIBS, .*mysqld.*) {
            use_libmysqlclient_r:LIBS += -lmysqlclient_r
            else:LIBS += -lmysqlclient
        }
    }
} else {
    !contains(LIBS, .*mysql.*):!contains(LIBS, .*mysqld.*):LIBS += -llibmysql
}

If the library name is different, it may be that Qt is not finding and therefore cannot create the driver. If this is the case, you can try to create a link between the library you have and the recognizable name.

Example:

ln -s libmysqlclient_r.so libmysqlclient_r.so.16 
  • the version of lib I own is eighteen, located in /usr/lib64/mysql/libmysqlclient.so.18.

  • I think if you renounce the 18 to only libmysqlclient_r.so also resolves.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.