I am trying to implement a database system in my Qt application. For this purpose, I am trying to use MySQL (with the related QMYSQL
driver). My class connection-function is written below.
Assuming that connection
is defined as a private
class member:
private:
QSqlDatabase connection;
we have the following:
database::database() : connection() {
this->connection.addDatabase("QMYSQL");
this->connection.setHostName(p.database->server_addr);
this->connection.setUserName(p.database->username);
this->connection.setPassword(p.database->password);
this->connection.setDatabaseName(p.database->database_name);
if (!connection.open())
this->error = this->connection.lastError().text();
else this->error = "";
}
I get database::error
with the value Driver not loaded Driver not loaded
(yes, it's written twice). I've seen here on Stack Overflow that I have to put the driver libraries in my application's path. I've done this and nothing happened. Below is a screenshot of the Qt libraries that are in my path.
EDIT
After calling QSqlDatabase::drivers()
, I found out that I have the drivers available. Below is the output ( int the show-more section of the message-box).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…