QtSql 程序无法使用共享库配置
两年前,我使用 QSqlDatabase 对象编写了一个示例程序,并使用依赖于静态库的 Qt 配置。它编译并按预期运行。去年的某个时候,我使用共享库重建了配置,现在出现以下错误。
这是错误:
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) publ
ic: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ
) referenced in function _main
...
debug\qtsql.exe : fatal error LNK1120: 12 unresolved externals
这是我的包含内容和 main.cpp 中对象的实例化:
#include <Qt>
#include <QtDebug>
#include <QtSql\QSqlDatabase>
#include <QFile>
#include <QtSql\QSqlQuery>
#include <QString>
#include <QVariant>
#include <QDate>
int main()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
...
另外,这是我的 .pro 文件:
TEMPLATE = app
TARGET =
DEPENDPATH += . versions
INCLUDEPATH += .
# Input
SOURCES += main.cpp
# Libraries
QMAKE_LIB_DIR += C:\\Qt\\4.7.0\\lib
我认为 .pro 文件中的最后一行会给我一个指向我可能需要的任何库的链接在 Qt 中。我非常不知道链接到 Qt .dll 需要什么。
为了让程序查看 QSqlDatabase 库,我缺少什么?
另外,即使我已经给了它头文件和库目录,我也必须指定库吗?
I wrote a sample program using QSqlDatabase object two years ago with a Qt configuration that depended on static libraries. It compiled ran as expected. Some time last year, I rebuilt the configuration using shared libraries and now I am getting the following errors.
Here is the error:
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) publ
ic: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ
) referenced in function _main
...
debug\qtsql.exe : fatal error LNK1120: 12 unresolved externals
Here are my includes and the instantiation of the object in main.cpp:
#include <Qt>
#include <QtDebug>
#include <QtSql\QSqlDatabase>
#include <QFile>
#include <QtSql\QSqlQuery>
#include <QString>
#include <QVariant>
#include <QDate>
int main()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
...
Also, here is my .pro file:
TEMPLATE = app
TARGET =
DEPENDPATH += . versions
INCLUDEPATH += .
# Input
SOURCES += main.cpp
# Libraries
QMAKE_LIB_DIR += C:\\Qt\\4.7.0\\lib
I thought that last line in the .pro file would give me a link to any library I might need in Qt. I'm pretty ignorant of what it takes to link to the Qt .dll's.
What am I missing to get the program to see the QSqlDatabase library?
Also, must I specify the library even though I have given it the header file and library directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里可能缺少 (链接到 qmake 文档)
这里是 Qt sql 示例的链接。也许您会在那里找到灵感/指导。
might be missing here (link to qmake docs)
Here is a link to the Qt sql examples. Perhaps you find inspiration/guidance there.