Portal:KB Code Snippets
All | Qt | Web | Java | Symbian C++
This page contains all official Code Snippets in the Nokia Developer Knowledge Base
Nokia Developer Code Snippets are easily reusable code blocks that perform a certain task or demonstrate an API use case. The example code has been created with the SDKs and been tested on real devices. Ideally each code snippet would contain a simple application that demonstrates the code in a practical way.
NEW! We have recently added a code snippets table that lists common mobile application use cases with links to corresponding code snippets. This way developers can now more easily find snippets in different programming languages and runtimes.
The Nokia Developer code snippets can be easily distinguished by a specific banner and the CS prefix in the title. Nokia Developer code snippets complement the existing Code Examples created by the developer community.
- CS001667 - Symbian^3 HDMI Output . . Forum Nokia KB
- Using projects version information from source code . . kratsan
- CS001665 - Enabling hardware floats on ARMV6 builds in Qt for Symbian projects . . Forum Nokia KB
- Qt for Symbian console applications . . treinio
- CS001564 - Implementing user-selectable autostart feature in Qt for Symbian . . Forum Nokia KB
- Twitter Integration to Qt using Qt WebKit . . chintandave_er
- Porting iPhone Web Apps to Qt using QtWebKit . . chintandave_er
- CS001642 - Using environment macros to differentiate platforms . . kratsan
- CS001351 - Adding Options menu, panes, and icon to a Qt for Symbian application . . seppo_fn
- Preventing elements to be behind fixed elements . . r2j7
- CS001641 - Showing Qt for Maemo applications built with the Nokia Qt SDK in the application menu . . Forum Nokia KB
- Overriding the minimum size constraint of QLayout . . kratsan
- How to disable dragging of images and text selection in web pages . . aleksi.hanninen
- Code snippets table for common use cases . . seppo_fn
- CS001614 - Transparent QDialog and QListWidget in Qt . . tepaa
- CS001578 - Floating elements inside block objects . . Forum Nokia KB
- CS001576 - Inserting custom text . . Forum Nokia KB
- CS001577 - Reading text continuously from input . . Forum Nokia KB
- CS001349 - Calculating text width in Qt . . liuxg
- CS001545 - Connecting to a QObjects signal with JavaScript slot in Qt WebKit . . Forum Nokia KB
- CS001543 - Exposing QObjects to Qt Webkit . . Forum Nokia KB
- CS001544 - Calling an exposed QObject slot from Qt WebKit with JavaScript . . Forum Nokia KB
- CS001556 - Enabling Qt Animation Framework in an application . . tepaa
- CS001557 - Animating graphics item position . . tepaa
- CS001558 - Animating graphics item rotation . . tepaa
- CS001559 - Animating graphics item fading . . tepaa
- CS001560 - Animating graphics item scaling . . tepaa
- CS001561 - Animating graphics item position and rotation simultaneously . . tepaa
- CS001495 - Display local web page with Qt WebKit . . Forum Nokia KB
- CS001350 - Generating random-value integers in Qt . . tepaa
- CS001515 - Transparent QPixmap picture . . tepaa
- CS001516 - Painting only the dirty area of the widget in Qt . . tepaa
- CS001514 - Rotate picture in Qt . . tepaa
- CS001519 - Minimise application and show task switcher in Qt for Maemo . . tepaa
- CS001411 - Retrieving location information . . ltomuta
- CS001496 - Gather data from web page with JavaScript, WebKit, and Qt . . taaidant
- CS001497 - Add data to a web page with JavaScript, WebKit, and Qt . . taaidant
- CS001500 - Reading big images in Qt . . seppo_fn
- CS001433 - Watching a YouTube video in Qt . . Mgoetz
- CS001431 - Creating an HTTP network request in Qt . . Mgoetz
- CS001430 - Creating QDomDocument in Qt . . Mgoetz
- CS001509 - Selecting data from a database without using SQL statements in Qt . . vkmunjpara
- CS001414 - Sending an MMS message . . chetanknanda
- CS001412 - Getting position data from TPositionInfoBase . . chetanknanda
- CS001144 - Handling pointer events . . chetanknanda
- CS001508 - Deleting data from a database in Qt . . tepaa
- CS001507 - Searching for data in a database in Qt . . tepaa
- CS001506 - Inserting a row into a database in Qt . . tepaa
- CS001505 - Creating a database table in Qt . . tepaa
- CS001504 - Creating an SQLite database in Qt . . tepaa
- Using QTestLib in S60 . . nayan_trivedi
- CS001510 - Using QDataWidgetMapper to show data from a database in Qt . . tepaa
- CS001503 - Using resources in Qt . . taaidant
- CS001502 - Applying a Qt style sheet to an application via QApplication . . taaidant
- CS001501 - Creating a gradient background for a QPushButton with style sheet . . taaidant
- CS001459 - Skinning the application . . Forum Nokia KB
- CS001436 - Using QXmlStreamReader to parse XML . . taaidant
- CS001437 - Listening for screen orientation changes in Qt . . tepaa
- CS001429 - Using QTextBrowser in Qt . . tepaa
- CS001438 - Listening for screen orientation changes . . tepaa
- CS001434 - Creating a loading animation with GIF, QMovie, and QLabel . . taaidant
- CS001432 - Handling an HTTP redirect with QNetworkAccessManager . . tepaa
- CS001435 - Using QLabel instead of QTextBrowser . . taaidant
- CS001428 - Using your own class as a signal and slot parameter in QThread . . seppo_fn
- CS001427 - Using threads in Qt . . seppo_fn
- CS001426 - Using common desktop services in Qt . . seppo_fn
- CS001425 - Loading and initialising a Qt plug-in dynamically . . seppo_fn
- CS001391 - Implementing the Qt plug-in interface . . seppo_fn
- CS001390 - Defining a Qt plug-in interface . . seppo_fn
- CS001424 - Using the DEPLOYMENT keyword in a Qt package file . . seppo_fn
- CS001423 - Exporting files into the emulator environment in Qt for Symbian . . seppo_fn
- CS001418 - Disconnecting a voice call with CTelephony . . seppo_fn
- CS001413 - Switching views . . tepaa
- CS001421 - Opening an HTML link in the web browser . . tepaa
- CS001420 - Opening an HTML document in the web browser . . tepaa
- CS001356 - Symbian C++: Listing messages in Inbox . . Forum Nokia KB
- CS001355 - Symbian C++: Listing available fonts . . Forum Nokia KB
- CS001416 - Listening for incoming SMS messages . . tepaa
- CS001415 - Deleting an incoming SMS message . . tepaa
- CS001410 - Calculating the distance between coordinates . . tepaa
- CS001417 - Change application MIME type mapping . . tepaa
- CS001419 - Sending an SMS message . . tepaa
- CS001354 - Launching a native application from Qt . . Forum Nokia KB
- CS001353 - Listening for Symbian Window Server events in Qt . . Forum Nokia KB
- CS001352 - Listening for Symbian key events in Qt . . Forum Nokia KB
- CS001348 - Changing QWidget background colour . . Forum Nokia KB
- CS001347 - Scaling QPixmap image . . Forum Nokia KB
- CS001346 - Scaling QGraphicsPixmapItem . . Forum Nokia KB
- CS001340 - QListView with a find pane . . Forum Nokia KB
- CS001339 - QListView with icons . . Forum Nokia KB
- CS001164 - Giving tactile feedback in touch UI applications . . lpvalente
- CS001309 - Maintaining square form for a widget in Qt . . Forum Nokia KB
- CS001308 - Implementing a layout manager in Qt . . Forum Nokia KB
- CS001294 - Setting the profile tones in active profile using Profile Engine Wrapper API . . Forum Nokia KB
- CS001166 - Interpolation . . Forum Nokia KB
- CS001165 - Implementing a custom CAknQueryDialog dialog . . Forum Nokia KB
- CS001163 - Detecting long tap in touch UI . . Forum Nokia KB
- CS001148 - Handling new touch-related MEikListBoxObserver events . . Forum Nokia KB
- CS001147 - Handling scalability in touch enabled device . . Forum Nokia KB
- CS001146 - Enabling drag events in touch-enabled devices . . Forum Nokia KB
- CS001145 - Pointer capturing in touch-enabled devices . . Forum Nokia KB
- CS001143 - Converting date and time to string in Open C++ . . Forum Nokia KB
- CS001142 - Shuffling data using STL random shuffle algorithm . . Forum Nokia KB
- CS001141 - Try and catch exception handling in Open C++ . . Forum Nokia KB
- CS001140 - Using periodic timer in RGA . . Forum Nokia KB
- CS001139 - Rotating images with AIW . . Forum Nokia KB
- CS001138 - Assign contact images with AIW . . Forum Nokia KB
- CS001137 - Routing a voice call between the earpiece and the loudspeaker . . Forum Nokia KB
- CS001136 - Adding equalizer to the audio player . . Forum Nokia KB
- CS001135 - Adding reverb to the audio player . . Forum Nokia KB
- CS001134 - Adding stereo widening to the audio player . . Forum Nokia KB
- CS001133 - Adding bass boost to the audio player . . Forum Nokia KB
- CS001132 - Adding listener's location effects to the audio player . . Forum Nokia KB
- CS001131 - Adding source location effects to the audio player . . Forum Nokia KB
- CS001130 - Adding doppler effects to the audio player . . Forum Nokia KB
- CS001121 - Showing count in the navi pane . . Forum Nokia KB
- CS001120 - Monitoring alarms . . Forum Nokia KB
- CS001119 - Playing a message with the native message reader . . Forum Nokia KB
- CS001118 - Creating a radio button settings page . . Forum Nokia KB
- CS001117 - Catching the menu open and close events . . Forum Nokia KB
- CS001116 - Checking the file I/O status in Open C++ . . Forum Nokia KB
- CS001115 - Reading and writing binary files in Open C++ . . Forum Nokia KB
- CS001114 - Reading and writing text files in Open C++ . . Forum Nokia KB
- CS001113 - Drawing a line with RGA . . Forum Nokia KB
- CS001112 - Text input with RGA . . Forum Nokia KB
- CS001111 - Detecting focus change with RGA . . Forum Nokia KB
- CS001110 - Fading effect with RGA . . Forum Nokia KB
- CS001109 - Scaling an image with RGA . . Forum Nokia KB
- CS001102 - One-second timer implementation using Open C++ . . Forum Nokia KB
- CS001101 - Checking if a file exists in C and C++ . . Forum Nokia KB
- CS001100 - Converting strings and numbers using string streams . . Forum Nokia KB
- CS001099 - Sorting class and struct types using STL sort . . Forum Nokia KB
- CS001098 - Sorting predefined types using STL sort . . Forum Nokia KB
- CS001097 - Creating dependencies to other components . . Forum Nokia KB
- CS001062 - Showing a global progress dialog using CAknGlobalProgressDialog . . Forum Nokia KB
- CS001061 - Showing a global list query using CAknGlobalListQuery . . Forum Nokia KB
- CS001060 - Showing a global confirmation query using CAknGlobalConfirmationQuery . . Forum Nokia KB
- CS001059 - Showing a global message query using CAknGlobalMsgQuery . . Forum Nokia KB
- CS001056 - Creating a password dialog with secret editors . . Forum Nokia KB
- CS001057 - Getting Eikon environment pointer . . Forum Nokia KB
- CS001055 - Creating a confirmation query dialog with an animation . . Forum Nokia KB
- CS001054 - Checking whether a certain MIME type is supported . . Forum Nokia KB
- CS001053 - Copying content to predefined directories with CDocumentHandler . . Forum Nokia KB
- CS001052 - Opening a file using CDocumentHandler . . Forum Nokia KB
- CS001050 - Creating a recognizer plug-in for a MIME type . . Forum Nokia KB
- CS001049 - Avoid flickering with double buffering . . Forum Nokia KB



At Symbian Press, we've recently created a set of Carbide templates for our Quick Recipes book. We used the templates to make a wizard to create entire examples from the book's sample code. It allows developers to create fully personalised example code, and include their own copyright notice, project name and UIDs. Noticing this was a useful way of distributing example code, we've been trying to see where else it could work.
We saw on the Forum Nokia Wiki you have a collection of code snippets, and wondered if these would be a useful plugin to distribute as wizards to create the example code.The plugin would allow the user to click "File >New > Symbian OS C++ Class" and use the sub menu to generate code confirming to FN Wiki code snippets under the folder name "Forum Nokia Code Snippets". Our summer intern created a small example of what this plugin would be like which we can supply to you (uploaded here Media:KB code snippets templates 1.0.0.1.zip). Upon extracting it into your carbide plugins folder, it should just work.
We would like to hear your opinion on the plugin; improvements that could be made, considerations that should be taken, or simply whether or not it would be a practical idea. We know of several advantages: + The plugin povides the user with a quick and easy way of getting the code from your website to their project + The code can be personalised, app names changed, etc. + It allows users who need the same code over and over to have it at the ready in their Carbide workspace, so that they need not keep referring to the website
We also know of its weaknesses: - Some code is too small or too incomplete to warrant a whole class being created for it - From my own experience of programming, I've always thought that it was much easier to find example code on a website, copy and paste it into my project, and then work around trying to fit it in and personalise it. For code that was easy enough just to copy into a class here and there, the approach of following a wizard would seem to be making too much work for myself. - The Symbian C++ Class page will be full of templates that the user might never use.
It's totally up to you - if you want to take these over and extend them, and supply on the wiki or elsewhere for developers to download, you're very welcome.
Jo Stichbury, Symbian Press