Unable to open sqlite database
I have a simple app that I am doing that will load a list for my inventory. I am doing this to learn a little bit about Qt because it looks really neat.
I have a few windows and a database that all those windows pull data from. I get 8 compile errors when following the built in examples (though they all are for in memory databases)
the errors are
undefined reference to `_imp__ZN12QSqlDatabase17defaultConnectionE'
undefined reference to `_imp__ZN12QSqlDatabase11addDatabaseERK7QStringS2_'
undefined reference to `_imp__ZN12QSqlDatabaseD1Ev'
undefined reference to `_imp__ZN12QSqlDatabase15setDatbaseNameERK7QString'
undefined reference to `_imp__ZN12QSqlDatabase4openEv'
undefined reference to `_imp__ZN12QSqlDatabaseD1Ev'
undefined reference to `_imp__ZN12QSqlDatabaseD1Ev'
collect2: Id returned 1 exit status
here is my connection header
connection.h
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QtSql/QSqlDatabase>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:\\Inventory.db");
if (db.open()) {
return true;
}
return false;
}
#endif // CONNECTION_H
the only thing I have done with connection.h is import it into mainwindow.cpp
I haven't found any real world examples (not examples, tutorials I mean) of sqlite usage (I don't see how an in memory sqlite database is helpful for a lot of people [though I am highly novice])
Thank you for any help SO
开发者_StackOverflowThese are imported into mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlTableModel>
#include "connection.h"
Add the following file to your *.pro file:
QT += sql
and do a qmake and build.
精彩评论