QT访问数据库:应用提示Driver not loaded

  • 在QT中运行完全正确
  • 错误截图
  • 解决办法1

我用的是MySQL。我把libmysql.dll复制到应用程序的目录下,即可正常访问数据库。

  • 解决办法2

    bool open_work_db()
    {
    QString info = "support drivers:";
    for (int i=0; i<QSqlDatabase::drivers().size(); i++)
    {
    info += "/"+QSqlDatabase::drivers().at(i);
    }
    QMessageBox::information(nullptr, "提示", info, QMessageBox::Ok);

    复制代码
      QLibrary library1("sqldrivers\\qsqlite.dll");
      if (!library1.load()) {
          QMessageBox::information(nullptr, "提示", library1.errorString(), QMessageBox::Ok);
      }
    
      QLibrary library2("libmysql.dll");
      if (!library2.load()) {
          QMessageBox::information(nullptr, "提示", library2.errorString(), QMessageBox::Ok);
      }
    
      QLibrary library3("sqldrivers\\qsqlmysql.dll");
      if (!library3.load()) {
          QMessageBox::information(nullptr, "提示", library3.errorString(), QMessageBox::Ok);
      }
    
      return true;

    }

检查加载情况。

  • 解决办法3

MySqL路径未设。

此电脑,属性,高级系统设置,环境变量:

相关推荐
NGC_661111 分钟前
Java反射
数据库
huahailing102415 分钟前
Spring Boot 异步事务最佳实践:TransactionTemplate 实战指南
数据库·spring boot·后端
Data_Journal16 分钟前
如何将网站数据抓取到 Excel:一步步指南
大数据·开发语言·数据库·人工智能·php
米码收割机22 分钟前
【AI】OpenClaw问题排查
开发语言·数据库·c++·python
色空大师33 分钟前
【mysql建表避坑指南】
数据库·mysql
V1ncent Chen1 小时前
从零学SQL 02 MySQL架构介绍
数据库·sql·mysql·架构·数据分析
大母猴啃编程1 小时前
MySQL内置函数
数据库·sql·mysql·adb
@小匠1 小时前
Spring-Gateway-理论知识总结/常问面试题
数据库·spring·gateway
逍遥德1 小时前
postgresql数据库连接问题
数据库·postgresql
此方ls1 小时前
Redis源码研读八——listpack.c 1080-1528行
c语言·数据库·redis