VS编译QT程序调用SQLite数据库研究

VS编译QT程序调用SQLite数据库研究,第1张

概述环境: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

环境: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 "
                     "to build it.\n\n"
                     "Click Cancel to exit."), QMessageBox::Cancel);
        return false;
    }
 
    Qsqlquery query;
    query.exec("create table person (ID int primary key, "
               "firstname varchar(20), lastname varchar(20))");
    query.exec("insert into person values(101, 'Danny', 'Young')");
    query.exec("insert into person values(102, 'Christine', 'Holand')");
    query.exec("insert into person values(103, 'lars', 'Gordon')");
    query.exec("insert into person values(104, 'Roberto', 'Robitaille')");
    query.exec("insert into person values(105, 'Maria', 'Papadopoulos')");
 
    query.exec("create table items (ID int primary key,"
                                             "imagefile int,"
                                             "itemtype varchar(20),"
                                             "description varchar(100))");
    query.exec("insert into items "
               "values(0, 0, 'Qt',"
               "'Qt is a full development framework with tools designed to "
               "streamline the creation of stunning applications and  "
               "amazing user interfaces for desktop, embedded and mobile "
               "platforms.')");
    query.exec("insert into items "
               "values(1, 1, 'Qt Quick',"
               "'Qt Quick is a collection of techniques designed to help "
               "developers create intuitive, modern-looking, and fluID "
               "user interfaces using a CSS & JavaScript like language.')");
    query.exec("insert into items "
               "values(2, 2, 'Qt Creator',"
               "'Qt Creator is a powerful cross-platform integrated "
               "development environment (IDE), including UI design tools "
               "and on-device deBUGging.')");
    query.exec("insert into items "
               "values(3, 3, 'Qt Project',"
               "'The Qt Project governs the open source development of Qt, "
               "allowing anyone wanting to contribute to join the effort "
               "through a meritocratic structure of approvers and "
               "maintainers.')");
 
    query.exec("create table images (itemID int, file varchar(20))");
    query.exec("insert into images values(0, 'images/qt-logo.png')");
    query.exec("insert into images values(1, 'images/qt-quick.png')");
    query.exec("insert into images values(2, 'images/qt-creator.png')");
    query.exec("insert into images values(3, 'images/qt-project.png')");
 
    return true;
}
总结

以上是内存溢出为你收集整理的VS编译QT程序调用SQLite数据库研究全部内容,希望文章能够帮你解决VS编译QT程序调用SQLite数据库研究所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1166680.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存