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 loaded
an 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 plugins
the folder
My Qt plugins path
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\plugins
Find sqldrivers
the 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-debug
that
statement will be output (because I only kept the qsqlite.dll file)
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.