QMYSQL driver not loaded QtCreator

4

I'm 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 qt-mysql and% pro QT += sql . What should I do in addition to have a connection?

Note:

Version of Qt = 5.2.1

SO = GNU / Linux Fedora

    
asked by anonymous 18.03.2014 / 23:30

2 answers

1

I solved installing 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.

    
19.03.2014 / 12:12
0

Make sure the mysql library is in a location accessible to Qt (% with%,% with% or something).

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

/usr/lib/ or /usr/lib/i386-linux-gnu or libmysqlclient_r.so

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

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 can not create the driver. If so, 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 
    
19.03.2014 / 02:42