我最近将我的机器更新到最新版本的Fedora Linux 27和Qt 5.10.0。 Qt框架是使用我通常做的脱机安装程序qt-opensource-linux-x64-5.10.0安装的。安装期间检查了所有选项,以确保安装了所有插件,源和库。这也是我通常在更新后进行全新安装Qt的方式。
现在问题是没有加载MySQL驱动程序
QSqlDatabase: QMYSQL driver not loaded
以前在Qt 5.8或5.7等早期版本中,通过链接正确版本的libmysqlclient.so或从Src目录重新编译它来解决此问题。但现在根本没有用。
所以这是需要MySQL的Qt程序的ldd
linux-vdso.so.1 (0x00007ffc13709000)
libmysqlclient.so.21 => /usr/lib64/mysql/libmysqlclient.so.21 (0x00007f59732cb000)
libzmq.so.5 => /usr/local/lib/libzmq.so.5 (0x00007f5973045000)
libQt5WebEngineWidgets.so.5 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5WebEngineWidgets.so.5 (0x00007f5972e04000)
libQt5PrintSupport.so.5 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5PrintSupport.so.5 (0x00007f5972b97000)
libQt5Widgets.so.5 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/lib/libQt5Widgets.so.5 (0x00007f597235e000)
可以看出这需要已经安装的最新版mysql libmysqlclient.so.21
这是/opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so的ldd输出
linux-vdso.so.1 (0x00007ffeb8bf8000)
libQt5Sql.so.5 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f60cd408000)
libQt5Core.so.5 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f60cccba000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f60cca9b000)
libmysqlclient.so.18 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f60cc715000)
libm.so.6 => /lib64/libm.so.6 (0x00007f60cc3c0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f60cc1a9000)
libc.so.6 => /lib64/libc.so.6 (0x00007f60cbdc6000)
libz.so.1 => /lib64/libz.so.1 (0x00007f60cbbaf000)
libicui18n.so.56 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007f60cb716000)
libicuuc.so.56 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007f60cb35e000)
libicudata.so.56 => /opt/Qt/Qt5.10.0/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007f60c997b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f60c9777000)
libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f60c9575000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f60c9261000)
/lib64/ld-linux-x86-64.so.2 (0x00007f60cd863000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f60c8fee000)
显然这表示libmysqlclient.so.18 =>找不到因为安装了最新版本的libmysqlclient.so.21。
现在,当我尝试重新编译驱动程序时,我遇到了一个重复的问题
qsql_mysql.cpp:235:9: error: ‘my_bool’ does not name a type; did you mean ‘_Bool’?
这就是我做的事情
cd /opt/Qt/Qt5.10.0/5.10.0/Src/qtbase/src/plugins/sqldrivers/mysql
/opt/Qt/Qt5.10.0/5.10.0/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib64/mysql" mysql.pro
make
Make失败并出现奇怪的错误
g++ -c -pipe -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -D_REENTRANT -fPIC -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtSql/5.10.0 -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtSql/5.10.0/QtSql -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtCore/5.10.0 -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtCore/5.10.0/QtCore -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtSql -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/include/QtCore -I.moc -isystem /usr/include/mysql -I/opt/Qt/Qt5.10.0/5.10.0/gcc_64/mkspecs/linux-g++ -o .obj/qsql_mysql.o qsql_mysql.cpp
qsql_mysql.cpp:235:9: error: ‘my_bool’ does not name a type; did you mean ‘_Bool’?
my_bool nullIndicator;
^~~~~~~
_Bool
qsql_mysql.cpp: In constructor ‘QMYSQLResultPrivate::QMyField::QMyField()’:
qsql_mysql.cpp:231:28: error: class ‘QMYSQLResultPrivate::QMyField’ does not have any field named ‘nullIndicator’
: outField(0), nullIndicator(false), bufLength(0ul),
^~~~~~~~~~~~~
qsql_mysql.cpp: In member function ‘bool QMYSQLResultPrivate::bindInValues()’:
qsql_mysql.cpp:430:28: error: ‘struct QMYSQLResultPrivate::QMyField’ has no member named ‘nullIndicator’
bind->is_null = &f.nullIndicator;
^~~~~~~~~~~~~
qsql_mysql.cpp: In member function ‘virtual QVariant QMYSQLResult::data(int)’:
qsql_mysql.cpp:641:15: error: ‘const struct QMYSQLResultPrivate::QMyField’ has no member named ‘nullIndicator’
if (f.nullIndicator)
^~~~~~~~~~~~~
qsql_mysql.cpp: In member function ‘virtual bool QMYSQLResult::isNull(int)’:
qsql_mysql.cpp:734:35: error: ‘const struct QMYSQLResultPrivate::QMyField’ has no member named ‘nullIndicator’
return d->fields.at(field).nullIndicator;
^~~~~~~~~~~~~
qsql_mysql.cpp: In member function ‘virtual bool QMYSQLResult::exec()’:
qsql_mysql.cpp:987:13: error: ‘my_bool’ was not declared in this scope
QVector<my_bool> nullVector;
^~~~~~~
qsql_mysql.cpp:987:13: note: suggested alternative: ‘_Bool’
QVector<my_bool> nullVector;
^~~~~~~
_Bool
qsql_mysql.cpp:987:20: error: template argument 1 is invalid
QVector<my_bool> nullVector;
^
qsql_mysql.cpp:1001:20: error: request for member ‘resize’ in ‘nullVector’, which is of non-class type ‘int’
nullVector.resize(values.count());
^~~~~~
qsql_mysql.cpp:1008:25: error: invalid types ‘int[int]’ for array subscript
nullVector[i] = static_cast<my_bool>(val.isNull());
^
qsql_mysql.cpp:1008:41: error: ‘my_bool’ does not name a type; did you mean ‘_Bool’?
nullVector[i] = static_cast<my_bool>(val.isNull());
^~~~~~~
_Bool
qsql_mysql.cpp:1009:46: error: invalid types ‘int[int]’ for array subscript
currBind->is_null = &nullVector[i];
^
qsql_mysql.cpp:1105:17: error: expected ‘;’ before ‘update_max_length’
my_bool update_max_length = true;
^~~~~~~~~~~~~~~~~
qsql_mysql.cpp:1114:72: error: ‘update_max_length’ was not declared in this scope
mysql_stmt_attr_set(d->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &update_max_length);
^~~~~~~~~~~~~~~~~
qsql_mysql.cpp: In member function ‘virtual bool QMYSQLDriver::open(const QString&, const QString&, const QString&, const QString&, int, const QString&)’:
qsql_mysql.cpp:1316:5: error: ‘my_bool’ was not declared in this scope
my_bool reconnect=false;
^~~~~~~
qsql_mysql.cpp:1316:5: note: suggested alternative: ‘_Bool’
my_bool reconnect=false;
^~~~~~~
_Bool
qsql_mysql.cpp:1334:21: error: ‘reconnect’ was not declared in this scope
reconnect = true;
^~~~~~~~~
qsql_mysql.cpp:1334:21: note: suggested alternative: ‘connect’
reconnect = true;
^~~~~~~~~
connect
qsql_mysql.cpp:1415:13: error: ‘reconnect’ was not declared in this scope
if (reconnect)
^~~~~~~~~
qsql_mysql.cpp:1415:13: note: suggested alternative: ‘connect’
if (reconnect)
^~~~~~~~~
connect
make: *** [Makefile:806: .obj/qsql_mysql.o] Error 1
说真的,我已经使用Qt多年了,而且在设置MySQL驱动程序时我从未遇到过这个问题。最奇怪的是,现在机器已经更新了所有最新版本。
请让我知道如何解决这个问题。现在已经在互联网上搜索了近一个星期,但没有解决这个错误的方法。我尝试过的所有内容总是以错误
结束qsql_mysql.cpp:235:9: error: ‘my_bool’ does not name a type; did you mean ‘_Bool’?
答案 0 :(得分:0)
所以最终找到了解决方案。我不得不做一个Fedora 27的全新安装,这次安装了Fedora 25中的前一个MySQL版本
dnf install https://dev.mysql.com/get/mysql57-community-release-fc25-9.noarch.rpm
dnf install mysql-community-server
还安装了所有其他依赖项。之后,像往常一样从离线包中安装了Qt 5.10.0。然后重新编译了sqldrivers,它运行顺利,没有显示任何错误。
所以我猜 MySQL 8.0 与Qt目前不兼容。
答案 1 :(得分:0)
我在QT论坛上找到了另一个人的解决方案:https://forum.qt.io/topic/114022/different-versions-of-qt-with-different-versions-of-mysql
只需打开文件qsql_mysql.cpp并添加“ typedef bool my_bool;”。在包含定义的初始标头之后。
那你应该很好。