The first tips you’ll need before start programming for Symbian using Qt

Last weekend I made my first Qt/Symbian mobile application. It was a very simple project, and its only purpose was to learn how to program for Symbian platform. I made a small application to search information about movies in TheMovieDb, and its source code is available at my github profile.

A Qt/Symbian app is something very close to a normal Qt-based application for desktop, but there are some little differences that can make you confused and some tips you may need, here are my advices for some pitfalls I’ve found.

Instead of showing widgets, add them to a QStackedWidget

(that’s the best solution I’ve found, but it seems to have other solutions)

In desktop Qt, you create a new QWidget and call show() to create a new window containing that widget. This won’t work with Symbian. When you do that, all you’ll get is a small, transparent widget at the corner of your screen.

The solution is to get the QMainWindow of your application, add a QStackedWidget as its central widget and add your new widgets into this QStackedWidget.

Every new widget must be added to QStackedWidget. It sounds painful, but Qt documentation tells us that when a widget is added to a QStackedWidget, the QStackedWidget becomes its parent.

When you create the first widget and add it to the stack, our QStackedWidget becomes its parent. So, to create a second widget and add it to the stack, you create your new widget as you do normally and asks the parent of the first widget – the QStackWidget! – to add it to the stack.

// Create your widget
QWidget *someWidget = new QWidget(parent());

// Get the reference to our QStackedWidget casting the widget parent
QStackedWidget *stackedWidget = (QStackedWidget*) parent();

// Add the widget

Creating menus and associating to positive and negative buttons

Nokia cell phones, even the cheaper ones, have options associated to the positive and negative buttons. Take a look on this picture of an old N70:

In the picture above, the positive action is Options, the negative option is Back. Creating options like these for your widget is quite simple.

In your widget’s source code, put the following lines in your constructor. Behold the lines where we use setSoftKeyRole to associate the action to a key. In my example, I have a “Back” shortcut and a “Details” shortcut, that access some slots.

// Register the negative action</pre>
<pre>QAction *backToMainScreenAction = new QAction("Back", this);
connect(backToMainScreenAction, SIGNAL(triggered()), SLOT(removeWidget()));

// Register the negative action
QAction *selectResultAction = new QAction("Details", this);
connect(selectResultAction, SIGNAL(triggered()), SLOT(showDetailsAboutTheCurrentItem()));
This code will register the action of each widget. But to make the options show in the screen, we must make the widget's container – the <strong>QStackedWidget</strong>! – register these actions in the menu every time the widget is created. I put the following lines in the same file where's my main window containing the QStackedWidget. First we create the following slot:</pre>
// This is a slot!
void MainWindow::updateActions() {
    QWidget *currentWidget = stackedWidget->currentWidget();

In the class’s constructor, we connect the stacked widget’s signals that are emmited when a widget is added or removed to the slot above:

connect(stackedWidget, SIGNAL(currentChanged(int)), SLOT(updateActions()));
connect(stackedWidget, SIGNAL(widgetRemoved(int)), SLOT(updateActions()));

Don’t believe the Nokia simulator

It’s still experimental. Sometimes you may think you made a mistake and have a bug, but you don’t. The simulator sometimes is confused with menus and soft buttons. If you get lost with your code and can’t find the causes of some obscure bug, try your application with a real device.

Good luck with the Remote Compiler

It’s still experimental too. When I tried to use it, I got some short error messages whose source I couldn’t discover. So, if you don’t use Windows (like me), prepare a virtual machine running Qt SDK on Windows.

44 Responses

  1. sell laptop May 11, 2016 / 3:56

    Find out how much you could earn for your old laptop with Cash in your Gadgets.

  2. BNP2 May 11, 2016 / 3:58

    Multi-lab offer BNP 2 Machinable Aluminium Nitride in blocks, rods, sheets and finished components for industries including aerospace.

  3. CISSP testinside June 9, 2016 / 4:06

    The solution is to get the QMainWindow of your application, add a QStackedWidget as its central widget and add your new widgets into this QStackedWidget.

  4. beck July 7, 2016 / 7:23

    download showbox and lets enjoy the online unlimited movies for free. download now for android download

  5. bhopdi k July 27, 2016 / 8:52

    terrariumTV app for movie streaming. now available for android smartphones and other devices too. checkout now this amazing app

  6. Alan August 10, 2016 / 7:06

    Very interesting blog examcollection 70-486. A lot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definitely interested in this one. examcollection 70-487

  7. buddi lane August 24, 2016 / 9:58

    here are some tips for students i.e What do you have to do?, Create a life schedule, Be flexible but realistic, Allow time for planning to avoid repetition, Avoid procrastination and distraction
    tips for students

  8. Google Chrome August 26, 2016 / 10:18

    Excellent post, it is Very interesting to read. in here great effort done here by admin i want to visit your site again and again, keep it up admin.,,,, thanks

  9. essay uk October 15, 2016 / 17:45

    Software developer need some form of tips before starting. The programming needs the initial working for such action. I lead for the timely action for the programming purpose.

  10. Android Tool November 18, 2016 / 6:36

    In here great and good information share… Thanks admin keep it up

  11. Academic Papers January 24, 2017 / 8:34

    Good to see your application. I hope that with hardworking, you will be able to make more improvements.

  12. Game Killer APK April 2, 2017 / 8:47

    Great post. This is interesting and informative post. Thanks.

  13. Faraz July 23, 2017 / 23:56

    I like this one of the best posting.

  14. Terrarium tv apk August 5, 2017 / 7:05

    Great Blog,
    click Terrarium tv apk and downloading the terrarium TV App for the online streaming the Latest TV Shows and Movies like Action, Horror, for free watch and downloading process are available for free of cost.

  15. NBA 2K17 APK October 15, 2017 / 17:19

    Hy admin, thanks for sharing this great thought. such a nice post.

  16. make money online November 5, 2017 / 21:20

    Great publish. Looking ahead some much more make money online associated submit from your facet.

  17. make money online December 2, 2017 / 19:52

    thanks for sharing effective ways that can help my business

  18. Apental Calc APK January 29, 2018 / 23:17

    Excellent Post, I found very useful content here, keep it up admin.

  19. Nokia Phoenix February 28, 2018 / 5:18

    really great work keep it up and thanks you for sharing.

Leave a Reply to Apental Calc APK Cancel reply

Your email address will not be published. Required fields are marked *