The Nokia N900 Blog |
| More Qt development – MVC and Maemo 5 widgets Posted: 13 Dec 2010 12:56 PM PST Some time ago I’ve started more technical part of this blog by presenting possibilities of Nokia Qt SDK and testing directly on N900. I may not be best suited for teaching but I can point out some interesting plots where to start and where to look. So let’s get to something more technical, this time – the code.
First of all Model-View-Controller, design pattern used for Qt widgets. Idea is pretty simple, to create widget we need Controller, from which we can manage its visual features, behavior and properties. Second of all most of widgets need data, enclosed in Model, for exaple combo box needs values that will show on the list of drop-down menu. Models can be created and added to widget with setModel() method of Controller. Third part, View provides actual UI part of widget, what we can see on screen when widget is shown in our application. So how to bring widget to screen, what is actually needed? If it comes to simple widgets, like button (QPushButton) it’s enough to create it (actually to create Controller) and put on screen. When we want to use some more complex widgets, like drop-down list it’s possible to supply it with Model enclosing data shown in drop-down menu. Most of Qt widgets have default View, so for simple applications you don’t need to take care of this part.
So now something for N900, among Qt modules we can find QtMaemo5 with some widgets specific for Maemo 5. You can try more yourself, but let’s take QMaemo5ValueButton for example. It’s finger friendly button that allows to choose option and displays this option in specified place on button. To give choice we can use QMaemo5ListPickSelector widget, invoked by pressing button, but it needs it’s own data (here’s the place where MVC works). We can construct our Model using QStandardItemModel, which is structured like table and for each row we can use QStandardItem with specified text. So let’s create few rows, append it to model and see how it works. If you’re interested in code lying behind this exampe you can download test application and try it yourself. I encourage you to create new project yourself and try few of widgets to be more familiar. You can find many examples in Qt documentation. This was example of something that works out of the box (Maemo 5 widgets) and if you check attached application also something that actually doesn’t do anything for now (QPushButton). If you have a look at the code you can see how to use few of Qt and QtMaemo5 widgets (controllers to be exact) and how to construct and add model to one. Next time we can use some more Qt magic to make button work. So… untill next time! – MJ |
| You are subscribed to email updates from Nokia N900 Blog | Apps | Games | Themes | Wallpapers | Hacks To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
| Google Inc., 20 West Kinzie, Chicago IL USA 60610 | |



