I'm trying to create an SQLite database in Qt:
#include <QtCore/QCoreApplication>
#include <QtSql/QSqlDatabase>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:\\Users\\Tanner\\Desktop\\db.sqlite");
return a.exec();
}
The output:
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:8: error: undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:8: error: undefined reference to `imp___ZN12QSqlDatabase11addDatabaseERK7QStringS2'
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:8: error: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:9: error: undefined reference to `_imp___ZN12QSqlDatabase15setDatabaseNameERK7QString'
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:11: error: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'
C:\Users\Tanner\qt\sqltest-build-desktop..\sqltest\main.cpp:11: error: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'
:-1: error: collect2: ld returned 1 exit status
I added extra slashes to the filepath because the compiler kept complaining about character escaping. Could that have anything to do with it? If so, how can I enter the path without it thinking I'm trying to escape the next character?
I was missing QT += sql
in the .pro file.