环境:win8 + VS2008 +QT4.8.1 + QT Creator2.4.1,QT4.8.1是利用vs2008静态编译的
问题描述:
直接运行QT自带的SQLite操作例子工程tableModel,用QT自带的编译器MinGW编译运行没有问题,但是把QT工程转成VS工程后,用VS编译没有问题,运行的时候调用db.open的时候失败,失败的原因是“diverError=Driver not loaded”
问题解决研究:
1.把QT4.8.1利用vs2008重新静态编译,要求编译的时候把sql和SQlite部分加入,尝试后不行。
2.把plugins文件夹下面的sqldrivers文件夹直接复制到执行程序同级目录里面,尝试后不行。
未完继续研究。。。
参考文章:
http://www.qtcn.org/bbs/simple/?t35292.html
http://blog.csdn.net/shuixin536/article/details/8562639
http://www.qtcentre.org/threads/32585-QT-amp-SQLite-driver-not-loaded
http://stackoverflow.com/questions/5151279/qsqlite-driver-not-loaded-where-to-put-qt-database-driver-plugins
http://stackoverflow.com/questions/32442744/qsqlite-driver-not-loaded
代码例子:
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "