Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

enter image description here

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).

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
620 views
Welcome To Ask or Share your Answers For Others

1 Answer

For mingw and Windows: Download the C (not c++) connector from: https://dev.mysql.com/downloads/connector/c/, then copy the library: libmysql.dll, to the folder: D:Qt5.5mingw492_32in. This should solve the problem for the not loaded driver.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...