I have a SQLite database for my Qt application. I assume that it would be logical to add the database as a resource.
I can't get my app to compile with the embedded resource.
connection.h
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":/data/ShippingData.db3");
if (!db.open())
{
QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}
#endif // CONNECTION_H
assets.qrc
<RCC>
<qresource prefix="/data">
<file>ShippingData.db3</file>
</qresource>
</RCC>
My sqlite database right now is like this
app.pro
file.h
file.cpp
data/ShippingData.db3
Build Issue (From Qt Creator)
No rule to make target `../TimePlotter/Shipping.db3', needed by `debug/qrc_assets.cpp'. Stop.
I tried changing my resource layout because it from the message the compiler isn't going into the data/ folder where the database is. I get the exact same build issue with this resource file
<RCC>
<qresource>
<file>data/ShippingData.db3</file>
</qresource>
</RCC>
TimePlotter.pro
#-------------------------------------------------
#
# Project created by QtCreator 2010-11-21T03:18:17
#
#-------------------------------------------------
QT += core gui
TARGET = TimePlotter
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
time.cpp
clients.cpp
printTime.cpp
HEADERS += mainwindow.h
time.h
clients.h
printTime.h
connection.h
FORMS += mainwindow.ui
time.ui
clients.ui
printTime.ui
RESOURCES +=
assets.qrc
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…