我有一个适用于我的Qt应用程序的SQLite数据库。我认为将数据库添加为资源是合乎逻辑的。Qt中的嵌入式数据库
我不能让我的应用程序与嵌入式资源进行编译。
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>
我的SQLite数据库现在的问题是这样的
app.pro
file.h
file.cpp
data/ShippingData.db3
构建的问题(从Qt Creator中)
No rule to make target `../TimePlotter/Shipping.db3', needed by `debug/qrc_assets.cpp'. Stop.
我试着改变我的资源布局,因为它从编译器没有进入数据库所在的数据/文件夹的消息中。我得到这个资源文件
<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
能否请您发表您的.pro文件也?这将有助于理解。谢谢。 – 2010-11-23 15:16:25