[英]QT SQLite not working in Embedded device
我正在使用 QT 框架。 基本上我正在为 ARM 设备创建应用程序。
现在,我使用 SQLite 创建了示例应用程序,用于 DB 工作。 事情是一个在我的桌面上工作,但是当我为设备交叉编译它并试图在我的设备中执行它时出现错误。
所以我记录了一些错误信息。 最后我发现数据库文件创建成功但无法在设备中创建表。
是不是因为 memory 问题?
代码:
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(););
}
好的。 另一个快速问题-> 是否可以在嵌入式设备中创建数据库文件并执行查询。 在我的设备中可用的免费 memory 为 9MB。
谢谢,毗湿奴
我认为你应该使用
CREATE TABLE IF NOT EXISTS songsList
sql 声明而不是
create table songsList
否则一旦创建了表,你第二次尝试执行它,你可能会得到一个错误。
除此之外,我没有看到问题,但谁知道......我希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.