0

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?

jetimms
  • 417
  • 1
  • 5
  • 23

1 Answers1

2
CONFIG += qt
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.

Ronny Brendel
  • 4,777
  • 5
  • 35
  • 55
  • Thanks for your input Ronny. I won't be able to attempt your fix for a few days. – jetimms Apr 03 '11 at 18:43
  • Ronny, you're suggestion almost worked, but your link led me to the answer. I had to do this to the .pro file: CONFIG += qt and on the next line QT += sql. Thanks again. – jetimms Apr 04 '11 at 20:07