我正在使用QT框架。基本上我正在爲ARM設備創建應用程序。QT SQLite無法在嵌入式設備中工作
現在我已經使用SQLite for DB工作創建了示例應用程序。事情是,一個人在我的桌面上工作,但當我交叉編譯它的設備,並試圖執行它在我的設備獲取錯誤。
所以我記錄了一些錯誤消息。最後,我發現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(););
}
好吧!還有一個快速問題 - >是否可以在嵌入式設備中創建DB文件並執行查詢。在我的設備中,可用內存爲9MB。
感謝, 毗溼奴
改善你的錯誤處理代碼,至少記錄或顯示QSqlDatabase.lastError()。的值。多多益善。 – 2011-05-25 11:55:34
謝謝!讓我試試看,如果可能的話會發布錯誤號碼 – vishnu 2011-05-25 12:22:06