【发布时间】:2011-06-13 18:52:29
【问题描述】:
我正在使用 QT 框架。基本上我正在为 ARM 设备创建应用程序。
现在我已经使用 SQLite 创建了示例应用程序,用于 DB 工作。事情是一个在我的桌面上工作,但是当我为设备交叉编译它并试图在我的设备中执行它时出现错误。
所以我记录了一些错误消息。最后我发现数据库文件创建成功但无法在设备中创建表。
是因为内存不足的问题吗?
代码:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("songs.db");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
//return false;
debugLog("#fileListThread::run()-> Unable to establish a database connection.."<<db.lastError(););
}
else
{
debugLog("#fileListThread::run()-> opened songs.db successfully..");
}
QSqlQuery query;
bool queryStatus = query.exec("create table songsList (id int primary key, "
"Song varchar(20), Artist varchar(20),Producer varchar(20))");
if(queryStatus)
{
debugLog("#fileListThread::run()-> created table in songs DB successfully..");
}
else
{
debugLog("#fileListThread::run()-> failed to create table in songs DB.."<<query.lastError(););
}
好的!另一个快速问题-> 是否可以在嵌入式设备中创建数据库文件并执行查询。在我的设备中可用的可用内存为 9MB。
谢谢, 毗湿奴
【问题讨论】:
-
改进你的错误处理代码,至少记录或显示 QSqlDatabase.lastError().number 的值。越多越好。
-
谢谢!让我试试,如果可能的话会发布错误号