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路径未设。

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

相关推荐
eggwyw1 小时前
完美解决phpstudy安装后mysql无法启动
数据库·mysql
LaughingZhu1 小时前
Product Hunt 每日热榜 | 2026-03-23
数据库·人工智能·经验分享·神经网络·chatgpt
2401_894241921 小时前
用Pygame开发你的第一个小游戏
jvm·数据库·python
java修仙传1 小时前
MySQL 事务隔离级别详解
数据库·mysql·oracle
Irissgwe1 小时前
MySQL存储过程和触发器专题
数据库·mysql·oracle
椎4952 小时前
Redis day02-应用-实战-黑马点评-短信登录
数据库·redis·spring
瀚高PG实验室2 小时前
易智瑞GeoScene Pro连接瀚高安全版数据库 458
数据库·安全·瀚高数据库
551只玄猫2 小时前
【数据库原理 实验报告3】索引的创建以及数据更新
数据库·sql·课程设计·实验报告·操作系统原理
加农炮手Jinx2 小时前
Flutter for OpenHarmony:postgrest 直接访问 PostgreSQL 数据库的 RESTful 客户端(Supabase 核心驱动) 深度解析与鸿蒙适配指南
数据库·flutter·华为·postgresql·restful·harmonyos·鸿蒙