专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > QT开发

Qt使用SQL的有关问题

发布时间:2010-05-30 20:03:38 文章来源:www.iduyao.cn 采编人员:星星草
Qt使用SQL的问题
我刚开始学Qt,工程里按教程使用了Sql,代码如下:

bool MainWindow::initDatabase()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("127.0.0.1");
    db.setDatabaseName("loader");
    db.setUserName("root");
    db.setPassword("root");
    if(!db.open())
    {
        QMessageBox::critical(this,QString::fromStdWString(L"连接数据库失败"), db.lastError().text());
        return false;
    }
    return true;
}


pro文件里也添加了 QT += sql
但编译的时候提示找不到定义,但我的pro文件里不是添加了sql模块吗?开发环境是Qt5.2+VS2010+WINXP
各位大哥有知道的吗?谢谢了


mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QSqlError::~QSqlError(void)" (__imp_??1QSqlError@@QAE@XZ),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class QString __thiscall QSqlError::text(void)const " (__imp_?text@QSqlError@@QBE?AVQString@@XZ),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class QSqlError __thiscall QSqlDatabase::lastError(void)const " (__imp_?lastError@QSqlDatabase@@QBE?AVQSqlError@@XZ),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: bool __thiscall QSqlDatabase::open(void)" (__imp_?open@QSqlDatabase@@QAE_NXZ),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QSqlDatabase::setPassword(class QString const &)" (__imp_?setPassword@QSqlDatabase@@QAEXABVQString@@@Z),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QSqlDatabase::setUserName(class QString const &)" (__imp_?setUserName@QSqlDatabase@@QAEXABVQString@@@Z),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QSqlDatabase::setDatabaseName(class QString const &)" (__imp_?setDatabaseName@QSqlDatabase@@QAEXABVQString@@@Z),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QSqlDatabase::setHostName(class QString const &)" (__imp_?setHostName@QSqlDatabase@@QAEXABVQString@@@Z),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static class QSqlDatabase __cdecl QSqlDatabase::addDatabase(class QString const &,class QString const &)" (__imp_?addDatabase@QSqlDatabase@@SA?AV1@ABVQString@@0@Z),该符号在函数 "private: bool __thiscall MainWindow::initDatabase(void)" (?initDatabase@MainWindow@@AAE_NXZ) 中被引用
mainwindow.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: static char * QSqlDatabase::defaultConnection" (__imp_?defaultConnection@QSqlDatabase@@2PADA)
debugMeter.exe : fatal error LNK1120: 11 个无法解析的外部命令

------解决方案--------------------
安装了MySql的驱动了没有?
------解决方案--------------------
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: