Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

c++ - QMYSQL driver not loaded on Windows

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...