时间:2021-07-01 10:21:17 帮助过:12人阅读
从qt5.2开始,qt版本应该是自带了qt链接mysql的驱动的,但是我这儿就出现问题了。。加载失败,但是如果加载QSQLITE的驱动是能成功的。。
实验代码如下:
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Available database is:";QStringList drivers = QSqlDatabase::drivers();for (QString driver : drivers) qDebug() << driver;QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");qDebug() << "mysql db is avaliable?" << db.isValid();return 0;
}
实验输出结果如下:
Available database is:
"QSQLITE" "QMYSQL" "QMYSQL3" "QODBC" "QODBC3" "QPSQL" "QPSQL7"
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
mysql db is avaliable? false
请各位大大指点一二。