{"id":124,"date":"2011-01-11T23:16:47","date_gmt":"2011-01-11T12:16:47","guid":{"rendered":"http:\/\/www.samontab.com\/web\/?p=124"},"modified":"2021-03-03T09:49:10","modified_gmt":"2021-03-02T22:49:10","slug":"how-to-create-your-first-application-for-the-nokia-n900-using-qt","status":"publish","type":"post","link":"https:\/\/www.samontab.com\/web\/2011\/01\/how-to-create-your-first-application-for-the-nokia-n900-using-qt\/","title":{"rendered":"How to Create Your First Application for the Nokia N900 using Qt"},"content":{"rendered":"<p>Nokia&#8217;s <a href=\"https:\/\/maemo.nokia.com\/n900\/\">N900<\/a> is a great smartphone. Actually it is a mobile computer running Linux. It has a touchscreen and a real keyboard as well as many embedded goodies: proximity and ambient light sensors, tri-axial accelerometer, camera, Bluetooth, Wi-Fi, GPS and IR. This makes the N900 the perfect device for your next hacking project or cool new application.<\/p>\n<p>The first step for creating apps for the N900 is to download and install the <a title=\"Nokia Qt SDK\" href=\"https:\/\/www.forum.nokia.com\/Develop\/Qt\/\">Nokia Qt SDK<\/a>. Qt is a very powerful SDK for creating applications for many environments, such as Windows, Linux, Mac, Maemo (this is what the N900 runs), Symbian, and Windows CE. That means that you only need to code once and you have native applications for all those environments. Nice.<\/p>\n<p>After Nokia Qt SDK is installed, open Qt Creator which is the IDE included with Qt. You should see something like this:<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/qtwin1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-126 alignnone\" title=\"qtwin\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/qtwin1-300x230.png\" alt=\"Nokia qt sdk for windows\" width=\"300\" height=\"230\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/qtwin1-300x230.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/qtwin1.png 869w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now, you need to create a new project. Go to <strong>File-&gt;New File or Project<\/strong>. There, under <strong>Qt C++ Project<\/strong>, you need to select <strong>Mobile Qt Application<\/strong> and click <strong>Choose<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/mobileqt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-127\" title=\"mobileqt\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/mobileqt-300x255.png\" alt=\"\" width=\"300\" height=\"255\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/mobileqt-300x255.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/mobileqt.png 570w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now you need to input the name and path of the project. Make sure that you <strong>do not use any spaces or special characters<\/strong> in either the name or the path of the project.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-129\" title=\"name\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/name-300x210.png\" alt=\"\" width=\"300\" height=\"210\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/name-300x210.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/name.png 555w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In the next window you will define the targets of your project. The options shown will depend on the specific SDKs that you have installed on your computer. At least you should have Maemo, Qt Simulator and Symbian Device since all of them are part of the Nokia Qt SDK. <strong>Select Maemo and Qt Simulator<\/strong>. Maemo is the platform for the N900 and the Qt Simulator is useful for design and debug on the PC.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/maemo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-130\" title=\"maemo\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/maemo-300x195.png\" alt=\"\" width=\"300\" height=\"195\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/maemo-300x195.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/maemo.png 539w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Next you will see the details of the classes that will be generated for you. Leave everything as default. It will create a\u00c2\u00a0 class called <em>MainWindow<\/em> derived from <em>QMainWindow<\/em>. Nothing to worry here, basically it is a class that represents a window. There are three files that will be created for this class; the <em>mainwindow.cpp<\/em> which holds the implementation of the methods of the class, <em>mainwindow.h<\/em> which defines the class itself and lists the methods, and<em> mainwindow.ui<\/em> which generates the UI based on the graphical designer inside Qt Creator.<strong> Just press Next<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/window.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-131\" title=\"window\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/window-300x230.png\" alt=\"\" width=\"300\" height=\"230\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/window-300x230.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/window.png 539w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now you will see the summary of the project. <strong>Click on Finish<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/end.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-135\" title=\"end\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/end-300x223.png\" alt=\"\" width=\"300\" height=\"223\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/end-300x223.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/end.png 555w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now you have a blank window and different controls that you can drag and drop into it. You can add buttons, text edits, combo boxes, calendars, and many more. Try dragging a couple of controls and looking at their properties on the right side. You can erase any control by just selecting it and pressing the Delete key.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/blankscreen2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-134\" title=\"blankscreen\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/blankscreen2-300x189.png\" alt=\"\" width=\"300\" height=\"189\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/blankscreen2-300x189.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/blankscreen2.png 944w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Let&#8217;s create a very simple application, something that sums two numbers. First, we need to add a <em>Layout<\/em>. A Layout brings order to the application&#8217;s items, and makes sure that it will look good on any platform. There are different types of layouts: <em>horizontal<\/em>, <em>vertical<\/em>, <em>form <\/em>and <em>grid<\/em>. Vertical and horizontal layouts are straightforward since they represent just a list of items on each direction. If you want to put two items per row, you can use the form layout. This layout is perfectly suited for aligning each text label with its corresponding text edit. If you have a more complex application UI, you can use the grid layout which is more flexible. For this simple application I will use the Form Layout. Just drag it to the window. A red rectangle should appear.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/formLayout.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-136\" title=\"formLayout\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/formLayout-300x161.png\" alt=\"\" width=\"300\" height=\"161\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/formLayout-300x161.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/formLayout-1024x551.png 1024w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/formLayout.png 1102w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now lets put some controls on the layout. I will be using three <em>Text Edits<\/em>, one for each number and one for the sum of them. You can find them under the <em>Input Widgets<\/em> category. Also, I will be using two <em>Labels<\/em>, found under <em>Display Widgets<\/em> and a <em>Push Button<\/em>, found under the <em>Buttons<\/em> category. Drag and drop them inside the red rectangle so that you see something like this:<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/form.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-137\" title=\"form\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/form.png\" alt=\"\" width=\"256\" height=\"186\" \/><\/a><\/p>\n<p>Now lets configure each item. You can double click on each of them to change the text or to input default values. If you click on an item it will be selected, and all of its properties will be shown on the right side. Select each line edit and change its <em>objectName<\/em> property to <em>number1<\/em>, <em>number2<\/em> and <em>sum<\/em> accordingly. Change the push button objectName to <em>sumNumbers<\/em>. The last thing that you need to do here is to set the <em>sizePolicy<\/em> for each item. Select every item and under sizePolicy, for horizontal and vertical select <strong>Expanding<\/strong>. This means that the items will expand to the correct size for any device. If you do not set these policies, probably you will not be able to see the items on the phone due to their small size.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/form2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-138\" title=\"form2\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/form2.png\" alt=\"\" width=\"211\" height=\"148\" \/><\/a><\/p>\n<p>OK, lets do some coding now. What we want the application to do is to sum <em>number1<\/em> and <em>number2<\/em> and output the result when the users clicks the <em>Sum<\/em> button. An easy way of accessing the code is to right click on the push button and select <strong>Go To Slot&#8230;<\/strong>. This will open a dialog with all the slots of that object. We are interested in the Clicked() slot, so select it and click OK. If you ask yourself what a slot is, just think of it as an event. Although if you really want to use Qt you should learn about <a title=\"Signals and Slots from Qt\" href=\"https:\/\/en.wikipedia.org\/wiki\/Signals_and_slots\">signals and slots<\/a>.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/slots.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-139\" title=\"slots\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/slots-300x125.png\" alt=\"\" width=\"300\" height=\"125\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/slots-300x125.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/slots.png 530w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Alright, now we are in the <em>Edit<\/em> tab of Qt Creator (before we were in the <em>Design<\/em> tab). This is where you can see all the source files and the actual code for the application. If you selected the Clicked() slot from the previous paragraph, a function will be created for you. Note that the function name, <strong>on_sumNumbers_clicked()<\/strong>,\u00c2\u00a0 has the name of the item (<em>sumNumbers<\/em>) and the slot (<em>clicked()<\/em>). This is the actual function that gets called when the sum button is pressed. Here is where we will do the actual coding.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nvoid MainWindow::on_sumNumbers_clicked()\r\n{\r\n \/\/anything from the user interface that we created is inside the ui object.\r\n\/\/first, get the two numbers as ints\r\n int number1 = ui-&gt;number1-&gt;text().toInt();\r\n int number2 = ui-&gt;number2-&gt;text().toInt();\r\n \/\/now sum the numbers\r\n int result = number1 + number2;\r\n \/\/finally store the result as text in the sum line edit\r\n ui-&gt;sum-&gt;setText(QString::number(result));\r\n}\r\n<\/pre>\n<p>OK, now the coding is done. Lets see it running on the emulator. Make sure that Qt Simulator is selected on the left side, above the green play button. To run it, just press the green play button. You should see something like this:<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/simulator2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-142\" title=\"simulator2\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/simulator2-300x183.png\" alt=\"\" width=\"300\" height=\"183\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/simulator2-300x183.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/simulator2.png 885w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Note that this is the actual N900 simulator. If you see a different phone, you can change it in the simulator window: Under the <em>View<\/em> category you will see a <em>Device<\/em> selection, just select <strong>Maemo Freemantle<\/strong> and the N900 should appear. Now you can use the application, input some values and after you click Sum, the result should appear correctly. If the application does not work properly at this stage, go back to the code and correct any mistakes.<\/p>\n<p>Once you have your application running in the simulator, it is time to compile it for the real N900 device. For doing that first close the simulator. Then, select <strong>Maemo<\/strong> above the green play symbol. Wait a couple of seconds until the Parsing, Scanning and Evaluating processes are done. After that, go to <strong>Build-&gt;Build All<\/strong>. Do not press the green arrow as you did before with the simulator. Wait until the building process is finished.<\/p>\n<p>Although the application was built successfully, there are a couple of things that we need to do before we can send the application to the device. First, go to the directory where the project was created. You should see the source files as well as the compiled application, <strong>myfirstmobileapp_0.0.1_armel.deb <\/strong>and a <strong>debian<\/strong> folder. Go inside that folder. There you will find a file called <strong>control<\/strong>. We need to edit this file. Drag and drop it inside Qt Creator (or use any other editor). The contents of the file will be something similar to this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSource: myfirstmobileapp\r\nSection: unknown\r\nPriority: extra\r\nMaintainer: unknown &lt;&gt;\r\nBuild-Depends: debhelper (&gt;= 5)\r\nStandards-Version: 3.7.3\r\nHomepage: &lt;insert the upstream URL, if relevant&gt;\r\nPackage: myfirstmobileapp\r\nArchitecture: any\r\nDepends: ${shlibs:Depends}, ${misc:Depends}\r\nDescription: &lt;insert up to 60 chars description&gt;\r\n &lt;insert long description, indented with spaces&gt;\r\n<\/pre>\n<p>The problem is in the <strong>Section: unknown<\/strong> statement. You need to change it to any valid section different than unknown. For example <strong>Section:  user\/development<\/strong> or <strong>Section: user\/other<\/strong> or any other valid section. If you don&#8217;t change this, you will receive an &#8220;<strong>incompatible application package<\/strong>&#8221; error when you try to install your application.<\/p>\n<p>Now we are going to add an icon for the application. Inside the Debian directory, you will see a folder with the name of your application, in my case <strong>myfirstmobileapp<\/strong>. Go inside that folder. There you will see two folders, <em>DEBIAN<\/em> and <em>usr<\/em>. Go inside the <em>usr <\/em>folder. There you will see three folders: <em>bin<\/em>, <em>local<\/em> and <em>sbin<\/em>. Create a new folder there called <em>share<\/em>. Go inside the newly created <em>share<\/em> folder. There, create two folders: <em>icons<\/em> and <em>applications<\/em>. Inside the icons folder, place the icon for your application, in png format and 64&#215;64 in size. Name it <em>myfirstmobileapp.png<\/em> or your specific application name. You can use this image as a template.<\/p>\n<p><a href=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/myfirstmobileapp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-143\" title=\"myfirstmobileapp\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2011\/01\/myfirstmobileapp.png\" alt=\"\" width=\"64\" height=\"64\" \/><\/a><\/p>\n<p>Now, go inside the Applications folder that you just created. There, create a folder called <em>hildon<\/em>. Go inside that folder. There, you have to create a text file called <strong>myfirstmobileapp.desktop<\/strong>. It should have the following contents:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;Desktop Entry]\r\nEncoding=UTF-8\r\nVersion=1.0\r\nType=Application\r\nName=myFirstMobileApp\r\nExec=\/usr\/local\/bin\/myFirstMobileApp\r\nIcon=myfirstmobileapp\r\nStartupWMClass=\r\nX-Window-Icon=myfirstmobileapp\r\nX-HildonDesk-ShowInToolbar=true\r\nX-Osso-Type=application\/x-executable\r\nTerminal=false\r\n<\/pre>\n<p>Make sure that you change <em>myfirstmobileapp<\/em> with your application name. Note that the icon filename does not need to have the PNG extension. After doing that, you are ready. Delete the application (<strong>myfirstmobileapp_0.0.1_armel.deb<\/strong>), go to Qt Creator and build it again. Now the generated application should install without a problem in your N900.<\/p>\n<p>Now you need to send the application deb file into your phone. You can do that easily by transferring the file via Bluetooth from your computer. You can select in the N900 to automatically open the file once the transfer is completed. That will launch the installation process. Also, you can use other methods such as an USB cable, or using internet and then use the file browser to navigate to the deb file and launch the installation process. That is all you need to install an application in the N900.<\/p>\n<p>If you are having problems following this tutorial, or if you just want fast results, you can download my sample project and use it as a template for your applications. This way you can focus more on creating cool applications instead of trying to compile them on the N900.<\/p>\n<p>Instructions:<\/p>\n<p>First, download the <a title=\"The sample project for N900 from samontab\" href=\"https:\/\/www.samontab.com\/web\/files\/myFirstMobileApp.zip\">project<\/a> and extract it. Then, double click on <em>myFirstMobileApp.pro<\/em>. This will open Qt Creator. Select Maemo and Qt Simulator on the Project Setup window. Then, select <strong>Maemo<\/strong> as the target (above the green arrow) and then build the project (<strong>Build-&gt;Build all<\/strong>).<\/p>\n<p>Now you need to make the corrections so that it installs on the N900. Download <a title=\"Fix for the project\" href=\"https:\/\/www.samontab.com\/web\/files\/share.zip\">this<\/a> and extract it. Put the <em>share<\/em> folder you just extracted inside the<em> debian\/myfirstmobileapp\/usr<\/em> folder . You should now see four directories under usr: bin, local, sbin and share.<\/p>\n<p>The next step is to overwrite the <em>control<\/em> file. Download the corrected file from <a title=\"Fix for the control file\" href=\"https:\/\/www.samontab.com\/web\/files\/control.zip\">here<\/a> and copy it into the <em>debian<\/em> directory. Overwrite the old control file.<\/p>\n<p>Now go to Qt Creator and select <strong>Build-&gt;Rebuild All<\/strong>. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nokia&#8217;s N900 is a great smartphone. Actually it is a mobile computer running Linux. It has a touchscreen and a real keyboard as well as many embedded goodies: proximity and ambient light sensors, tri-axial accelerometer, camera, Bluetooth, Wi-Fi, GPS and IR. This makes the N900 the perfect device for your next hacking project or cool [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,4],"tags":[14,15,13,12,17,11,9,10,18,8,20,16,19],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-open-source","category-programming","tag-app","tag-application","tag-demo","tag-first","tag-incompatible","tag-installation","tag-n900","tag-nokia","tag-package","tag-qt-2","tag-section","tag-tutorial","tag-unknown"],"_links":{"self":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":0,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}