Archive for the ‘Programming’ Category

Android SDK Linux quick setup

Thursday, June 30th, 2011

Android SDK setup for Linux is a bit different than in Windows. I wrote quick instructions to setup Android development environment in Linux:

1. Setup Java dev environment:

First you need to install JDK and Eclipse

sudo apt-get install sun-java6-jdk eclipse

2. Install Android SDK starter package

sudo wget

sudo tar -zxf android-sdk_r11-linux_x86.tgz

(Or download and extract manually from

3. Install & configure ADT plugin for Eclipse

  • Open Eclipse and select from menu Help -> Install New Software
  • Add software source by clicking Add and give some name to repository and the following address:
  • Select all tools and click next, next and accept the agreement and click finish
  • Restart Eclipse
  • After restart select Window -> Preferences… from Eclipse’s menu
  • Select Android from the left pane and set the Android SDK location to correspond with the directory where you extracted the started package in step 2

4. Install Android platforms and other components

Now you can download and install different Android platforms and create virtual images with SDK and AVD manager straight from Eclipse. (…or with android tool which is located in the sdk directory)

  • In Eclipse select Window -> Android SDK and AVD manager
  • From the left pane select Available packages and download & install the packages you want (Select 3rd party add-ons and Google APIs if you want to use e.g. Google Maps)
  • Platform tools will be downloaded to you SDK directory

5. Create test project and virtual images

Virtual images can be created with the Android SDK and AVD manager. Create and start one.

Now create new Android project:

  • Select File -> New Project -> Project...
  • Select Android -> Android project
  • Type in Project name, Package name and check build target from the list of downloaded & installed platforms. Click Finish
  • Run the project with Ctrl+F11, select Run as Android Application
  • Select a virtual image in where you want to run the application (or create one if you haven’t already)

6. Running applications in hardware devices

In Linux you have to manually add USB support for different device manufacturers.

Create and edit following file
sudo nano /etc/udev/rules.d/51-android.rules

Insert following text to the file:
SUBSYSTEM=="usb", SYSFS{idVendor}=="XXXX", MODE="0666"
where XXXX is the device manufacturers vendor ID. IDs are presented in the table below

Company USB Vendor ID
Acer 0502
Dell 413c
Foxconn 0489
Garmin-Asus 091E
Google 18d1
HTC 0bb4
Huawei 12d1
Kyocera 0482
LG 1004
Motorola 22b8
Nvidia 0955
Pantech 10A9
Samsung 04e8
Sharp 04dd
Sony Ericsson 0fce
ZTE 19D2

Set the permissions for the file:
chmod a+r /etc/udev/rules.d/51-android.rules

Now attach the device with usb cable and it should be recognized in the Run dialog.

PS. make sure you have turned the USB debugging on in the device (e.g. Settings -> Applications -> Development enable USB debugging)

WordPress blog contents to external page

Monday, April 18th, 2011

This blog’s content is created and running with WordPress, but other content in my web site is not. So I needed a way to export latest blog post titles from the WordPress’ MySql database to other (non-WordPress) pages.

Here’s a PHP snippet for that:

$connection = mysql_connect(“localhost”, “database_user”, “database_password”);
  1. mysql_select_db("database_table", $connection);
  3. $query = "SELECT post_status, post_date, guid, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0, 6";
  5. $result = mysql_query($query, $connection) or die("Query error!");
  7. echo "
  10. <h3>Blog updates:</h3>
  12. ";
  14. for ($i = 0; $i &lt; mysql_num_rows($result); $i++) {
  15.    $link = mysql_result($result, $i, "guid");
  16.    $title = mysql_result($result, $i, "post_title");
  18.    echo "
  20. <a href="$link">$title</a>
  22. ";
  23. }
  25. mysql_close($connection);

Just edit “database_user”, “database_password” and “database_table” to correspond with your WordPress settings and paste the code to a web page you want.

You can see this code working in a sidebar of the other pages on this site.

QMdiArea tabs with close button

Saturday, March 6th, 2010

If you want to build an application with multiple document interface and tabs, you don’t have the close buttons in the tabs by default. That’s why I’ve come up with a workaround to get those buttons in every tab. Here’s a code example:

  1. Q_FOREACH (QTabBar* tab, ui>mdiArea>findChildren())
  2. {
  3.    tab>setTabsClosable(true);
  4.    connect(tab, SIGNAL(tabCloseRequested(int)),
  5.                this, SLOT(closeTab(int)));
  6. }
  8. void MainWindow::closeTab(int i)
  9. {
  10.    QMdiSubWindow *sub = ui>mdiArea>subWindowList()[i];
  11.    QWidget *win = sub>widget();
  12.    win>close();
  13.    ui>mdiArea>setActiveSubWindow(sub);
  14.    ui>mdiArea>closeActiveSubWindow();
  15. }

Filtering relational tables in Qt Sql

Friday, February 19th, 2010

I have a database which I’m using in my program which has foreign keys with same column name as in the table which it’s related. So I tried to set a filter to the related tables using setFilter(“relationtable.fieldName = ‘value'”), but it’s not working. I found out that Qt makes aliases to the relation table. Qt’s reference manual says “The alias is is the relation’s table name and display column name joined by an underscore (e.g. tablename_columnname)”.

I tried that but I think there’s somekind of bug because the query still says it’s an unknown column. However, I looked through the Qt’s Sql source code and found a solution.

For the relation table name you should use name like relTblAl_2, where the number after the underscore is the foreign key column in the main table.


  1. relTableModel>setTable("MainTable");
  2. relTableModel>setRelation(2, QSqlRelation("RelationTable", "ID", "Name"));
  3. relTableModel>setFilter("relTblAl_2.Name = 'Example'");

In this example table named RelationTable is aliased as relTblAl_2. By using the alias you can filter the values in the relational table.

SpeedTest – Qt game

Saturday, February 6th, 2010

It’s just basic clicking game made in a couple of hours but it was  good way to find out how to do a cross-platform project with Qt.

It builds with no problems for Symbian and Windows platform and probably to others as well with some tweaks. Especially great was the Qt’s interface for symbian touch screen devices. Qt handles the touches as mouse clicks so it’s easy to do programs/games which uses the touch screen devices.

Only drawback for developing with Qt for Symbian is the lack of the smart installer atm(release date Q1/2010?). It means, that you have to include the Qt installer to the .sis file which increases the size of the program. In the future Qt is included to the mobile phones so we’ll just have to wait for that.

Project information:  SpeedTest

Testing applications with different Nokia phones

Wednesday, February 3rd, 2010

Nokia offers a great service for developers where you can test and install your applications with different Nokia mobile phones. All you need is an account for Nokia forums and you’re free to test different models.

List of available phone models

It’s a great tool to help you develop and test applications and verify the app’s functions without concretely owning all possible mobile phones. You can also use some debugging options in the service, like trace a Symbian panic information and text files in a real-time. You can also record the session with built-in screen capture.


The service is called Remote Device Access and it works with Java Runtime and browsers supported are Firefox v2+, Internet Explorer v7+, Opera v9.6+ and Safari v3+. It works with Google Chrome too.

Link: Remote Device Access

Locking screen orientation to landscape in Qt for Symbian

Sunday, January 31st, 2010

In my current project I’m programming a game for Symbian which will run only in landscape mode. So somehow I needed to lock the application to use only the landscape mode as some mobiles change the orientation automatically. I found a code snippet for that from Nokia’s forum.

The cone.lib, eikcore.lib, and avkon.lib Symbian libraries must be added to your Qt project:

  1. symbian: {
  2.     LIBS += lcone leikcore lavkon
  3. }

You also need some extra header files added to your source file:

  1. #ifdef Q_OS_SYMBIAN
  2. #include <eikenv.h>
  3. #include <eikappui.h>
  4. #include <aknenv.h>
  5. #include <aknappui.h>
  6. #endif

Create a window to your app and include the  following code before the window is shown. It will lock the orientation to landscape mode:

  1. CAknAppUi* appUi = dynamic_cast (CEikonEnv::Static()>AppUi());
  2. TRAPD(error,
  3. if (appUi) appUi>SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
  4. );

Now the orientation is locked and it will not change manually by user or automatically.