QT5.11.1+MSVC2015_64位下重新编译好的64位Qt 5.11.1的mysql驱动,mysql采用的版本是5.7.22。把qsqlmysql.dl放到QT5的plugins\sqldrivers下,把libmysql.dll放到QT5的bin目录下。在这个问题上纠结两三天,终于好了,希望可以帮你绕过这个坑。附上测试代码:
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QMYSQL", strConnection1);
db.setHostName(QObject::tr("localhost"));
db.setDatabaseName(QObject::tr("test"));
db.setUserName(QObject::tr("root"));
db.setPassword(QObject::tr(""));
if ( !db.open() )
{
QSqlError error = db.lastError();
qDebug() << "Failed to connect to root mysql admin: " << error.databaseText();
}
1