【发布时间】:2016-01-14 09:23:09
【问题描述】:
首先,非常感谢那些愿意花时间帮助我解决这个问题的人。在发帖之前,我在许多不同的论坛上进行了很多搜索,但似乎我遗漏了一些东西。
嗯,我正在使用 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
- 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... */
}
数据库.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());
}
}
}
【问题讨论】: