ubuntu10.04 Qt5.2.1链接mysql出现QMYSQL driver not loaded的问题!!!!
来源:互联网 发布:mysql unique 编辑:程序博客网 时间:2024/06/03 12:45
背景介绍:由于学校开设了数据库 课程,由此想用Qt来链接mysql来试试手~
可是在尝试C++ GUI Qt4这书的数据库例子时,就出现了QMYSQL driver not loaded 的问题
网上有很多办法,但是没有解决好问题的.......
情急之下翻墙去google看国外牛人是怎么解决的.........
果然发现了解决方法!以下是转载!
Qt 5.1.0 on Ubuntu Linux, MySQL database connection problem, driver not loaded problem
Problem description
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
false
Example Code to reproduce the error:
#include <QCoreApplication>
#include <QtSql>
int
main(
int
argc,
char
*argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase(
"QMYSQL"
);
db.setHostName(
"localhost"
);
db.setDatabaseName(
"test"
);
db.setUserName(
"test"
);
db.setPassword(
"xxxxxxxxxx"
);
bool
ok = db.open();
qDebug() << ok;
db.close();
return
a.exec();
}
WTF:
I saw available drivers right there -- f**king "QMYSQL" there, but why am I not be able to load it?!
Ok, ignore me.
Problem Explanation:
No matter it's there or not it still may cause an error -- if you know c++ well, you gotta know that a library dependency problem is a huge headache anyway. (well, some may argue that it's a problem not only within c++. ok, ok... you're right, so what?)
- If you're using Qt on Ubuntu Linux, and you're installing with the ".run" binary installer of Qt officially. They might have already install the MySQL plugins for you inside the folder:
$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/plugins
(my environment example is: /opt/Qt5.1/5.1.0/gcc_64/plugins/ folder).
- If you're using apt-get to install the qt5-default package, the plugins where mysql uses is located at:
/usr/lib/i386-linux-gnu/$QT_VERSION/plugins/ for 32bits ubuntu
or
/usr/lib/x86_64-linux-gnu/$QT_VERSION/plugins/ for 64bits ubuntu
How to check whether I have mysql driver, or have the right one
- Go to the plugins directory described above.
- Go inside sqldrivers directory.
- Check whether there is a library called libqsqlmysql.so inside.
If libqsqlmysql.so is inside, then you can get QMYSQL inside the QSqlDatabase: available drivers list described in the example code above.
However, the library is not granted to be working due to update of your mysql package or other misoperations.
Use the command below to check whether the library is under a library-dependency problem:
>> ldd libqsqlmysql.so
What generates in my environment is this:
You now may see the problem: libmysqlclient_r.so.16 => not found ---- there's a library he can't find. (Why cannot he find it? Because I updated the mysql package after I installed the Qt.)
Problem Solve
Recompile the plugin
- Download the latest source code of Qt from qt-project (It should be named like "qt-everywhere-opensource-src-version".tar.gz)
- unpack it and go to qtbase/src/plugins/sqldrivers/mysql/ directory
- >> qmake
- >> make
- It will generate the right lib file for you in the qtbase/plugins/sqldrivers/ directory
Check the recompiled the plugin
>> ldd libqsqlmysql.so
What generates in my environment is this:
With libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007f98f988d000) this library, it finally gets to the correct dependent library.
Copy back the library Copy back the correct libqsqlmysql.so to the place it should be in:
$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/plugins
or
/usr/lib/i386-linux-gnu/$QT_VERSION/plugins/
or
/usr/lib/x86_64-linux-gnu/$QT_VERSION/plugins/
Nota Bene:
- If you still cannot get to the right thing, you may have your environment set unproperly. Try this:
export
PATH=
"$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/bin/"
:$PATH
export
LD_LIBRARY_PATH=
"$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/lib/"
:$LD_LIBRARY_PATH
export
LD_LIBRARY_PATH=
"$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/plugins/"
:$LD_LIBRARY_PATH
export
LIBRARY_PATH=
"$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/lib/"
:$LIBRARY_PATH
export
LIBRARY_PATH=
"$QT_INSTALL_PLACE/$QT_VERSION_NUMBER/$COMPILE_TOOL_KIT_NAME/plugins/"
:$LIBRARY_PATH
My Environment Example:
export
PATH=
"/opt/Qt5.1/5.1.0/gcc_64/bin/"
:$PATH
export
LD_LIBRARY_PATH=
"/opt/Qt5.1/5.1.0/gcc_64/lib/"
:$LD_LIBRARY_PATH
export
LD_LIBRARY_PATH=
"/opt/Qt5.1/5.1.0/gcc_64/plugins/"
:$LD_LIBRARY_PATH
export
LIBRARY_PATH=
"/opt/Qt5.1/5.1.0/gcc_64/lib/"
:$LIBRARY_PATH
export
LIBRARY_PATH=
"/opt/Qt5.1/5.1.0/gcc_64/plugins/"
:$LIBRARY_PATH
This means you should have the plugins/ directory search availa
- ubuntu10.04 Qt5.2.1链接mysql出现QMYSQL driver not loaded的问题!!!!
- Qt5链接MySql--QMYSQL driver not loaded
- Qt5.4连接mysql出现QSqlDatabase: QMYSQL driver not loaded
- Qt5以上QMYSQL driver not loaded问题
- Qt5 编译MySQL驱动,仍然加载失败,出现QMYSQL driver not loaded
- Qt5.5连接mysql数据库提示QMYSQL driver not loaded
- QT5 解决QSqlDatabase: QMYSQL driver not loaded 问题
- Qt5.2.1中解决QSqlDatabase:QMySQL driver not loaded
- Qt5.7与MySQL5.7在win10下的连接问题(QMYSQL driver not loaded !)
- Qt连接MySQL出现QSqlDatabase: QMYSQL driver not loaded
- Qt连接MySQL出现QSqlDatabase: QMYSQL driver not loaded
- Qt连接MySQL出现QSqlDatabase: QMYSQL driver not loaded
- Qt5.4下连接Mysql,QSqlDatabase: QMYSQL driver not loaded,QSqlDatabase: available drivers: QSQLITE QMYSQL
- fedora 18~20 中Qt 5.2.1 解决连接mysql数据库出现QMYSQL driver not loaded的问题
- QMYSQL driver not loaded
- Windows下Qt连接Mysql数据库的方法,解决QSqlDatabase: QMYSQL driver not loaded 问题
- Windows下Qt连接Mysql数据库的方法,解决QSqlDatabase: QMYSQL driver not loaded 问题
- Ubuntu16.04 QT "QMYSQL driver not loaded on Ubuntu"问题
- POJ1979 Red and Black
- Objective-C ---分布式对象
- 学习计划[201405 ~ 201410]
- 在CentOS 6.3中安装与配置JDK-7
- w3shool中的TCP/IP (I)
- ubuntu10.04 Qt5.2.1链接mysql出现QMYSQL driver not loaded的问题!!!!
- struts2 get 和set 方法
- 函数指针
- cocos2dx游戏开发学习笔记2-从helloworld开始
- NYOJ 7 街区最短路径问题
- Java(TM) Platform SE binary 已停止工作
- Web Service概述 及 应用案例
- 纯CSS3文字效果推荐
- poj 1852 ants