开发者

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

开发者_StackOverflow

These 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜