首先,非常感謝那些需要時間來幫助我解決這個問題的人。在發佈之前,我在很多不同的論壇上搜索了很多,但似乎我錯過了一些東西。[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