problem using sqlite in QT4.7
I wrote a program using sqlite but when I run it there seems no sqlite support
Here is the information given by the QT creator: QSqlDatabase: QSQLITE driver not loaded QSqlDatabase: available drivers:
no available drivers!But there are sqlite4.dll,sqlodbc4.dll in the C:\Qt\2010.05\qt\plugins\sqldrivers directory why the program cannot detect where the drivers are? Should I recompile the Qt4.7 with -qt-sql-sqlite option? This seems the last resolution which is very time-consuming. Any suggestions? Thanks in ad开发者_开发知识库vance.
Well if you didn't compile qt with sql enabled then sql won't work. I would suggest you do that even though it may be time consuming. If you need it, that is the best way.
you need to put qsqlite4.dll
file within your sqldrivers
folder
What mode are you builing in - debug or release? If you're building in debug mode then you need debug version of the SQLite plugin called sqlite*d*4.dll not sqlite4.dll.
You can turn some useful debug info on by setting environment variable QT_DEBUG_PLUGINS=1
. If you do this and you'll get something like this
QFactoryLoader::QFactoryLoader() looking at "C:/Qt/4.7.0-mingw/plugins/sqldrivers/qsqlite4.dll"
In C:/Qt/4.7.0-mingw/plugins/sqldrivers/qsqlite4.dll:
Plugin uses incompatible Qt library
expected build key "Windows mingw debug full-config", got "Windows mingw release full-config"
you know you need debug version of the plugin.
Additionally, if there's some problem with finding plugins in the original plugins' folder (the one you gave in your question) you can create sqldrivers
folder in the folder of your app and copy sqlite*.dll
plugins there.
It's probably as simple as forgetting to specify the driver in the opening call:
QSqlDatabase::addDatabase("QSQLITE")
精彩评论