首先,非常感谢那些需要时间来帮助我解决这个问题的人。在发布之前,我在很多不同的论坛上搜索了很多,但似乎我错过了一些东西。[Qt] [QMYSQL]已部署的应用程序 - 驱动程序未加载
嗯,我正在使用Qt5.5/MySQL Server 5.6的Windows 7(64位)。 而我在Qt Creator上使用MinGW 5.5.0 32位(自动检测)。 这不是一个建立驱动程序的问题,它已经完成,它对于开发者来说是完美的。 :-) 我可以达到我的BD,做任何我想要的查询并检索/插入所有数据。
我正面临着在其他计算机上部署我的应用程序的问题。 我知道我必须将qsqlmysql.dll放在我的应用程序中的文件夹“sqldrivers”中。目录。比如将libmysql.dll也放在这个目录下。
所以我有类似如下的
- app目录
- APP.EXE
- 的libmysql.dll
- Qt5Core.dll
- Qt5Gui
- Qt5Sql
- Qt5Widget
- libwinpthread-1.DLL
- 的libstdC++ - 6.dll
- libgcc_s_dw2-1.dll
- 平台
- qwindow.dll
- sqldrivers
- qsqlmysql.dll
但当我释放的申请,我尝试从我用它开发的另一台计算机上运行它,我有一个“驱动程序不加载“错误...
到目前为止,我真的不知道我错过了什么...... 所以请,如果有人可以给我一些,它会真的非常感激!
我让你这是真正有用的,万一代码的一部分...
的main.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... */
}
Database.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());
}
}
}
你刚刚救了我的一天。这实际上是libmysql.dll在64位而不是32位...谢谢! – Tuvia