简体   繁体   中英

QMYSQL driver not loaded Qt 5.6 Linux Ubuntu 16.04

i know that these question asked many times but i try all solution here and from another site but all not working for me what i try is
1 - install libqt5sql5-mysql
2 - install libqt4-sql-mysql
3 - use QPluginLoader to load sql driver
4 - copy the folder of sql driver to my debug folder

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

i have this problem on windows i solve it by using mcsv 64 it doest work for 32 or for mingw compiler but i dont know how to solve this problem on linux
my os is
- ubuntu 16.04 LTS 64-bit
- Mysql compile machine is x86_64
code i use to connect to database

QSqlDatabase dp = QSqlDatabase::addDatabase("QMYSQL","first");
dp.setDatabaseName("Test");
dp.setHostName("localhost");
dp.setUserName("root");
dp.setPassword("root");
dp.setPort(3306);
if (dp.open()){
    QMessageBox::information(nullptr,"Succsefull","Connect To Mysql");
}
else{
    QMessageBox::critical(nullptr,"Error",dp.lastError().text());
}

Try to copy the sqldrivers folder to your debug folder and it should work. Else, try:

$ cd /opt/Qt5.2.0/5.2.0/gcc_64/plugins/sqldrivers 
$ ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so 
$ ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so.16

您可以从apt安装qtcreator,因为它具有一些编程所需的依赖项

sudo apt install qtcreator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM