Qt operation database error: QSqlDatabase: QSQLITE driver not loaded

After solving the database problem of Clion + Qt " Clion + Qt Adding SQLite Database ", I encountered a new problem. When running the program, QSqlDatabase: QSQLITE driver not loadedan error occurred.

Use the following statement to output the supported databases, and the output will be empty.

qDebug() << "sql drivers" << QSqlDatabase::drivers();

Finally, it was discovered that after adding the Sql module, it was not enough. The relevant dynamic link library also needed to be copied to the application running path.

solution

First, go to the Qt installation path and enter pluginsthe folder
My Qt plugins path

E:\Qt\Qt5.14.2\5.14.2\mingw73_64\plugins

Find sqldriversthe folder and copy the folder directly to the path of the executable program . Not in the project directory, (of course, there may be differences in different environments). For example, I am using the Qt program written by Clion, and the path is. Run it again, and cmake-build-debugthat
Insert image description here
Insert image description here
statement will be output (because I only kept the qsqlite.dll file)
Insert image description here

Notice

Although it has been said above, I have also tested it. It is not possible to copy the qsqlite.dll dynamic library file to the program root path alone. It must be in the sqldrivers folder.
Insert image description here

Guess you like

Origin blog.csdn.net/no_say_you_know/article/details/123782107#comments_28526446