gpt4 book ai didi

mysql - [Qt][QMYSQL] 已部署的应用程序 - 未加载驱动程序

转载 作者:行者123 更新时间:2023-11-28 23:48:07 28 4
gpt4 key购买 nike

首先,非常感谢那些愿意花时间帮助我解决这个问题的人。在此处发帖之前,我在许多不同的论坛上进行了大量搜索,但似乎遗漏了什么。

好吧,我正在使用 Qt5.5/MySQL Server 5.6 在 Windows 7(64 位)上工作。我在 Qt Creator(自动检测)上使用 MinGW 5.5.0 32 位。这不是构建驱动程序的问题,它已经完成并且非常适合开发人员。! :-)我可以访问我的 BD,执行任何我想要的查询并检索/插入所有数据。

我正面临将我的应用程序部署到其他计算机上的问题。我知道我必须将 qsqlmysql.dll 放在我的应用程序中的文件夹“sqldrivers”中。目录。比如把libmysql.dll也放在这个目录下。

所以我有类似下面的内容

  • 应用程序目录
    • App.exe
    • libmysql.dll
    • Qt5Core.dll
    • Qt5Gui
    • Qt5Sql
    • Qt5 微件
    • libwinpthread-1.dll
    • libstdc++-6.dll
    • libgcc_s_dw2-1.dll
    • 平台
      • qwindow.dll
    • sqldrivers
      • qsqlmysql.dll

但是当我发布应用程序并尝试从我用来开发的另一台计算机上运行它时,出现“未加载驱动程序”错误...

到目前为止,我真的不知道我错过了什么......所以,如果有人能给我一些,我将不胜感激!

我把真正有用的代码部分给了你,以防万一......

主要.cpp

QApplication a(argc, argv);
Maintenance w;
w.show();
return a.exec();

维护.cpp

void Maintenance::login(){
int db_select = 1;
this->maint_db = Database(db_select);

/* All that follow is linked to the login of user... */
}

数据库.cpp

Database::Database(int default_db)
{
this->db = QSqlDatabase::addDatabase("QMYSQL");
switch(default_db){
case 0:
this->db.setHostName("XXX.XX.XXX.XX");
this->db.setDatabaseName("maintenance_db");
this->db.setUserName("USERNAME");
this->db.setPassword("PASSWORD");
this->db.setPort(3306);
break;

// Only to make some trials in local
case 1:
this->db.setHostName("127.0.0.1");
this->db.setDatabaseName("maintenance_db");
this->db.setUserName("USERNAME");
this->db.setPassword("PASSWORD");
break;
}

/* I've added the following code to try to solve the problem

I retrieve that the available drivers are: QMYSQL / QMYSQL3
But all the information about the DB are empty (due to the unloaded driver I assume.)
And the error from *lastError()* is "Driver not loaded"
*/

QString my_drivers;
for(int i = 0; i < QSqlDatabase::drivers().length(); i++){
my_drivers = my_drivers + " / " + QSqlDatabase::drivers().at(i);
}
QString lib_path;
for(int i = 0; i < QApplication::libraryPaths().length(); i++){
lib_path = lib_path + " / " + QApplication::libraryPaths().at(i);
}

QString start = QString::number(QCoreApplication::startingUp());
QMessageBox::information(0, "BDD init",
"Drivers available: " + my_drivers
+ " \nHostname: " + this->db.hostName()
+ "\nDB name: " + this->db.databaseName()
+ "\nUsername: " + this->db.userName()
+ "\nPW: " + this->db.password()
+ "\n\n" + lib_path + "\n" + start
);

if(this->db.isOpen()){
QMessageBox::information(0, "BDD init", "Already open.");
}
else{
if(this->db.open()){
QMessageBox::information(0, "BDD init", "Opened.");
}
else{
QMessageBox::critical(0, "BDD init", "Not opened.\n" + this->db.lastError().text());
}
}
}

最佳答案

至少有 3 种可能的解决方案:

  1. 使用您最喜欢的进程监视器查找所有 .dll 路径都是正确的
  2. 确保所有 .dll 与您的 .exe 在同一个架构中,即 x86(32 位)
  3. 使用 QPluginLoader 进行调试

关于mysql - [Qt][QMYSQL] 已部署的应用程序 - 未加载驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33156663/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com