Hi, I tried it and unfortunately it does nos compile...
Qt Code:
  1. #include "phonebook.h"
  2. #include "ui_phonebook.h"
  3. #include <QMessageBox>
  4. #include <QDesktopservices.h>
  5. //./phonebook.db
  6. PhoneBook::PhoneBook(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::PhoneBook)
  9. {
  10. ui->setupUi(this);
  11.  
  12. database = new QSqlDatabase();
  13.  
  14. //set database driver to QSQLITE
  15. *database = QSqlDatabase::addDatabase("QSQLITE");
  16. // database->setDatabaseName(":memory:");
  17. //database->setDatabaseName("./phonebook.db");
  18. QString dbName = QDesktopServices::storageLocation (QDesktopServices::DataLocation) + "/phonebook.db";
  19. database->setDatabaseName(dbName);
  20.  
  21. //can be removed
  22. //database->setHostName("localhost");
  23. //database->setUserName("");
  24. //database->setPassword("");
  25.  
  26. if(!database->open()) {
  27. QMessageBox::warning(0,"Error",tr("Couldn't open database file: %1").arg(database->lastError().text()));
  28. }
  29.  
  30. QSqlQuery query;
  31. query.exec("CREATE TABLE IF NOT EXISTS Contacts (id int primary key, "
  32. "name varchar(20), mobile varchar(20),city varchar(20))");
  33. all_model = new QSqlTableModel(this, *database);
  34. updateTable();
  35.  
  36. search_model = new QSqlTableModel(this, *database);
  37. search_model->setTable("Contacts");
  38. }
To copy to clipboard, switch view to plain text mode 
But if I comment this line like this..
Qt Code:
  1. if(!database->open()) {
  2. QMessageBox::warning(0,"Error",tr("Couldn't open database file: %1"));//.arg(database->lastError().text()));
  3. }
To copy to clipboard, switch view to plain text mode 
and here is the result when compiled...
Qt Code:
  1. Executable file: 15482 2011-06-13T15:12:58 C:\QtSDK\Symbian\SDKs\Symbian1Qt473\\epoc32\release\gcce\urel\SQLite_example.exe
  2. Starting application...
  3. Application running with pid 4355.
  4. [Qt Message] QSqlQuery::exec: database not open
To copy to clipboard, switch view to plain text mode 

thanks,
lam-ang