You are on page 1of 24

Qt on Symbian

The Anatomy of an App

John Kern Member of Technical Staff Symbian Foundation

A brief history of Symbian
Founded back in 1980s Renamed Symbian Ltd in 2001 June 2008 - Nokia bought Symbian Ltd April 2009 - Symbian Foundation Formed October 2009 - Kernel EPL'ed February 2010 - Source Code completely EPL'ed

The Symbian Foundation
The People Technology Management Release and deployment Marketing Governance Resources - source documentation

Symbian OS - state of the art
kernel real time multithreading SMP-ready kernel security server architecture

Qt Evolution
Symbian^1 same as S60 5th Edition Symbian^2 and earlier - S60 Symbian^3 - Qt for S60 Smart installer - back to 3rd ed - FP1 Symbian^4 - UI (Orbit) Qt UI Extensions for Mobile APIs for phone specific functionality Mobile Extensions Qt Mobility project

Qt Web runtime Flash python J2ME

Good time to develop for Symbian
Pain points go away. Custom widgets Learning curve Focus on innovation, not infrastructure

Pain Points?
Qt descriptors => QString TRAP/Leave => C++ exceptions Active Object => signals/slot sqlite3 webkit Open C - provides a posix layer.

Example - Hello World
menu bar list widget menu item on Options double click on list item.

Decouples action from behavior It is async We will be using it UI but also applies to networking.

Menu Bar
verAction = new QAction(tr("&Version"),this); menuBar()->addAction(verAction); connect(verAction, SIGNAL(triggered()), this, SLOT(displayVersion()));

List Behavior
list of birds Double click?

birds << "Avocet" << "Sparrow" << "Crow" << "Sea gull" << "Kookaburra"; birdList = new QListWidget; setCentralWidget(birdList); birdList->addItems(birds); connect(birdList, SIGNAL(itemDoubleClicked ( QListWidgetItem * )), this, SLOT(displayBird(QListWidgetItem *)));

void MainWindow::displayBird ( QListWidgetItem * item ) { QMessageBox::information(this,"picked", item->text()); }

Simple UI - main()
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.createMenus(); w.setWindowTitle("Hello World!"); w.showMaximized(); return a.exec(); }

Example - Seafood
The Model-View pattern decouples data from UI. Fishes encapsulates uses SQLite3 widgets QStackedWidget QTabWidget QWebView QTableView

Stacks widgets on top of each other Only one visible at a time. Ours will contain QTabWidget QWebView QTableWidget

Tab Widget
three lists best ok worst

Tab Widget - construct
// Tab Widget - owns a list of QListWidget this->tabWidget = new QTabWidget; //best choice this->bestList = new QListWidget; this->bestList->addItems(this->fishDb->getBest()); this->tabWidget->addTab(this->bestList, "best"); // ... omitted ok and worst lists.

html drive by SQLite

SQLite - connecting to the DB
QSqlDatabase db; // Find SQLite driver db = QSqlDatabase::addDatabase("QSQLITE"); QString dbFile=QDesktopServices::storageLocation(QDesktopServices::DataLocation) + '/' // Qt Universal file separator + "seafood.db"; dbFile.replace("/","\\"); QFile f(dbFile); db.setDatabaseName(dbFile); // Open databasee if(!

SQLite - query
QString detailsInHtml; QSqlQuery query; query.prepare("select details from ecoDetails " "where fid in (select fid from fish where name = :name )"); query.bindValue(":name",name); if (!query.exec()) { QString errCode = "failed to get eco details " + query.lastError().text(); qWarning(errCode.toStdString().c_str()); } else { detailsInHtml.append("<html> <title>name</title> <body> <h2>Eco Details</h2> <ul> "); while ({ detailsInHtml.append( " <li>"); detailsInHtml.append( query.value(0).toString()); detailsInHtml.append( "</li> " ); } detailsInHtml.append("</ul> </body> </html> "); ...

Works well with Model/View Here UI designer one SQL query

newItem = new QTableWidgetItem(nutrition[Fishes::ECalories] ); this->ui->tableWidget->setItem(row++,COLUMN, newItem); newItem = new QTableWidgetItem(nutrition[Fishes::ETotalFat] ); this->ui->tableWidget->setItem(row++,COLUMN, newItem); newItem = new QTableWidgetItem(nutrition[Fishes::ETotalProtein] ); this->ui->tableWidget->setItem(row++,COLUMN, newItem); ....

Where to go from here?
Download Qt Creator