×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Porting Android (Java) applications to Qt

From Nokia Developer Wiki
Jump to: navigation, search
Raulherbster (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
 
(31 intermediate revisions by 13 users not shown)
Line 1: Line 1:
 +
{{Archived|timestamp=20120209055110|user=[[User:Hamishwillee|<br />----]]|This article is somewhat old, and though mostly valid, inaccurate at places. More recent porting from Android to Qt documentation is available as part of the [http://www.developer.nokia.com/Resources/Library/Porting_to_Qt/android-to-qt.html Porting to Qt Library]}}
 +
[[Category:Porting]][[Category:Qt]][[Category:Qt Mobility]][[Category:Symbian]][[Category:Android]][[Category:MeeGo Harmattan]]
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090407
 +
|author= [[User:Jaaura]]
 +
}}
 +
 +
 
=== Introduction ===
 
=== Introduction ===
  
As an initiative of [http://www.openhandsetalliance.com/ The Open Handset Alliance and Google], the Android has been developed as the first open and free platform for mobile phones. The project have been developed since November 5, 2007, when Google Inc., Intel, T-Mobile, Sprint, HTC, Qualcomm and Motorola decided to archive an ambitious goal: provide services so consumers would face a far better user experience.
+
As an initiative of [http://www.openhandsetalliance.com/ The Open Handset Alliance and Google], Android has been developed as the first open and free platform for mobile phones. The project has been developed since November 5, 2007, when Google Inc., Intel, T-Mobile, Sprint, HTC, Qualcomm and Motorola decided to achieve an ambitious goal: provide services so consumers would face a far better user experience.
  
An important point of Android platform is that handset manufacturers and wireless operators can provide suitable versions of Android for their products and services. This characteristic directly impacts on lower cost and innovative products. Then, Android can be considered a new and potential option on mobile platforms for smartphones.
+
An important point of the Android platform is that handset manufacturers and wireless operators can provide suitable versions of Android for their products and services. This characteristic directly impacts on lower cost and innovative products. Therefore, Android can be considered a new and potential option for mobile platforms for smartphones.
  
[[Image:Android.jpg‎]][[Image:Nokia-n97-2.jpg]]
+
[[File:Android.jpg‎]][[File:Nokia-n97-2.jpg]]
  
On the other hand, Qt has been considered as a powerful component on this newest mobile programming arena.  Qt is most notably used in Desktop applications, such as KDE, Opera, Skype and VirtualBox, but recently it has been ported to Nokia mobile platforms, such as S60 and maemo. Initially developed by Trolltech since 1991, Qt is released on two different licenses (open source and commercial), which should make Qt more suitable for non-GPL open source projects and for commercial users. In June 2008, Nokia acquired Trolltech to enable the acceleration of cross-platform software strategy for mobile devices and desktop applications. On September 29, 2008 Nokia renamed Trolltech to Qt Software.  
+
On the other hand, Qt has been considered a powerful component in this newest mobile programming arena.  Qt is most notably used in Desktop applications, such as KDE, Opera, Skype and VirtualBox, but recently it has been ported to Nokia mobile platforms, such as S60 and Maemo. Initially developed by Trolltech since 1991, Qt is released with two different licenses (open source and commercial), which should make Qt more suitable for non-GPL open source projects and for commercial users. In June 2008, Nokia acquired Trolltech to enable the acceleration of cross-platform software strategy for mobile devices and desktop applications. On September 29, 2008 Nokia renamed Trolltech to Qt.  
 
 
This article provides information that guide the development to port Android applications to Qt for S60.
+
This article provides information that guides development to port Android applications to Qt.
  
 
=== Overview of Android Platform ===
 
=== Overview of Android Platform ===
Android applications are develop with Java programming language (Dalvik virtual machine) and device services, such as touchscreen and storage features, can be access through Google services API. It is possible to run applications written in C or any other language, but the application have to be compiled to native code and run, but this development path is not officially supported by Google.
+
Android applications are developed with the Java programming language (Dalvik virtual machine), and device services, such as touchscreen and storage features, can be accessed through the Google services API. It is possible to run applications written in C or any other language, but the applications have to be compiled to native code and run; this development path is not officially supported by Google.
 +
 
 +
Since October 2008, Android has been available as an open source project (Apache License). Handset manufacturers and wireless operators are free do add closed and proprietary extensions to their products.
 +
 
 +
Although Android is based on a Linux kernel, according to Google, it is not a Linux operating system. In addition, it does not have a native windowing system, nor does it support the full set of standard Linux libraries, including the GNU C Library. This characteristic make it difficult to reuse existing Linux applications or libraries. Android does not use standard Java APIs, such as J2SE and J2ME. This prevents compatibility between Java applications written for those platforms and those for the Android platform. Android only reuses the Java language syntax, but does not provide the full-class libraries and APIs bundled with J2SE or J2ME.
  
Since October 2008, Android has been available as open source project (Apache License). Then,  handset manufacturers and wireless operators are free do add closed and proprietary extensions to their products.
+
The next picture shows the current Android architecture (from the Android Developer's Guide).
  
Although Android is based on a Linux kernel, according to Google, it is not a Linux operating system. In addition, it does not have a native windowing system, nor supports the full set of standard Linux libraries, including GNU C Library. This characteristic make it difficult to reuse existing Linux applications or libraries. Android does not use standard Java APIs, such as J2SE and J2ME. This prevents compatibility among Java applications written for those platforms and those for the Android platform. Android only reuses the Java language syntax, but does not provide the full-class libraries and APIs bundled with J2SE or J2ME.
+
[[File:Android-architecture.jpg‎]]
  
The next picture shows the current Android architecture (from Android Developer's Guide).
+
The system has access to mobile phone resources through system drivers, such as camera, display, WiFi and keypad drivers. Then, the next layer consists of libraries and the runtime system of Android. Finally, Android provides a set of libraries (Application Framework) so it is possible to extend them and create new applications.  
  
[[Image:Android-architecture.jpg‎]]
+
Android makes it possible to reuse components of other applications. For example, if you need to reuse a component that provides a suitable scroller and made it available to others, you can invoke such a component to do the work for you. Therefore, the system has been designed to start an application process when any part of it is needed, and instantiate the Java objects for that part. Therefore, Android does not provide an entry point, such as main function, but essential components: activity, services, broadcast receives and content providers.
  
The system has access to mobile phone resources through system drivers, such as camera, display, WiFi and keypads drivers. Then, the next layer consists of libraries and runtime system of Android. Finally, Android provides a set of libraries (Application Framework) so it is possible to extend them and create new applications.  
+
'''Activities''' represent screens on an Android application. From an activity, you can display buttons, labels, menus and much more. All activities subclass the ''android.app.Activity'' class. '''Services''' do not have visual appearance, but they run in the background. For example, a service may play music while the user performs other tasks. Each service extends the ''android.app.Service'' base class. '''Broadcast receives''' are components that receive and react to different broadcast announcements, for example, a message that the battery is low. All receivers extend the ''android.content.BroadcastReceive'' base class. A '''content provider''' is responsible for making an application's data available to other applications. Therefore with content providers, it is possible to share data between different applications. All content providers extend the ''android.content.ContentProvider'' base class.
  
Android makes it possible to reuse other components of other applications. For example, if you need to reuse a component that provides a suitable scroller and made it available to others, you can invoke such component to do the work for you. Therefore, the system has been designed to start an application process when any part of it is needed, and instantiate the Java objects for that part. Then, Android does not provide an entry point, such as main function, but essential components: activity, services, broadcast receives and content providers.
+
The Android development environment consists of: the Android SDK, Android source code and, optionally, IDEs that help make programming Android applications a lot quicker. The Android software development kit (SDK) consists of libraries and tools, including an emulator to run applications. The Android SDK is available for Windows, Mac OS X, and Linux. There are different IDEs that provide support for Android development, such as Eclipse (with the Eclipse plug-in for Android).
  
'''Activities''' represent screens on an Android application. From an activity, you can display buttons, labels, menus and much more. All activities subclasse ''android.app.Activity'' class. '''Services''' do not have visual appearance, but they runs on background. For example, a service play a music while the user perform other tasks. Each service extends the ''android.app.Service'' base class. '''Broadcast receives''' are components that receive and reacts to different broadcast announcements, for example, a message that the battery is low. All receivers extend the ''android.content.BroadcastReceive'' base class. A '''content provider''' are responsible to provide application's data available to other applications. Then, with content providers, it is possible to share data between different applications. All content providers extend the ''android.content.ContentProvider'' base class.
+
=== Overview of Qt ===
  
Android development environment consists of: Android SDK, Android source code and, optionally, IDEs that helps programming Android applications a lot quicker. Android software development kit (SDK) consists of libraries and tools, including an emulator to run applications. The Android SDK is available for Windows, Mac OS X, and Linux. There are different IDEs that provides support for Android development, such as Eclipse (Eclipse plug-in for Android).
+
Qt applications are developed with C++ enhanced with additional extensions implemented by a pre-processor that generates standard C++ code before compilation. Qt also provides bindings for several other programming languages, like Python, Ruby and Perl.
  
=== Overview of Qt S60 ===
+
[[File:Qts60.jpg]]
Qt applications are developed with C++ with several non-standard extensions implemented by an additional pre-processor that generates standard C++ code before compilation. Qt also provides bindings for several other programming languages, like Python, Ruby and Perl.
+
 
 
Qt is notably used because of its GUI widget, but also provides a set of non-GUI related features: SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling. Qt has being successfully ported to S60 Nokia platform. Qt for S60 will [http://www.qtsoftware.com/developer/technical-preview-qt-for-s60 “enable you to create advanced applications with innovative user experiences while getting to market quickly”]. Compared with Android, Qt is not supposed to be used as platform for mobile phones, but an interesting and easy-to-use programming framework that certainly brings a considerable contribution to mobile programing.
+
Qt is notably used because of its GUI widgets, but also provides a set of non-GUI related features: SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling. Qt has been successfully ported to the Nokia Symbian S60, Maemo, and MeeGo platforms. Qt will [http://developer.qt.nokia.com/wiki/Support_for_Symbian “enable you to create advanced applications with innovative user experiences while getting to market quickly”]. Compared with Android, Qt is an interesting and easy-to-use programming framework that certainly brings a considerable contribution to mobile programming as well as desktop application development.
  
Considering the fact that Qt has been recently ported to S60 platform, there are still some APIs that are not implemented such as camera and contacts modules. However, it is possible to access such system services thought callbacks to Symbian applications.  
+
[[File:Qt-architecture.png]]
  
[[Image:Qts60.jpg]]
+
Qt Mobility has been completely ported to Symbian, and commonly used mobile features are accessible through the [http://qt.nokia.com/products/qt-addons/mobility/ Qt Mobility APIs] such as camera, geolocation, and contacts APIs. There are rapid on-going progress of making all mobile features accessible, and some features which are not provided by Qt Mobility APIs can still be accessed through native Symbian APIs.
  
In order to develop Qt S60 applications, you need to install Qt S60 Nokia SDK, with consists libraries and tools (including the emulator for S60 environment). In addition, Carbide++ IDE (based on Eclipse framework) provides a full feature environment that helps a lot the developers. You can found interesting articles on Forum Nokia Wiki about Qt S60 (see [http://wiki.forum.nokia.com/index.php/Category:Qt_for_S60 Category Qt for S60]).
+
In order to develop Qt Symbian applications, you simply need to install the [http://www.developer.nokia.com/info/sw.nokia.com/id/e920da1a-5b18-42df-82c3-907413e525fb/Nokia_Qt_SDK.html Nokia Qt SDK], which contains Qt SDK, Qt Mobility SDK, Qt Creator, Qt Simulator for Symbian and N900, and libraries, tools (including the emulator for S60 environment), and all documentation you need to get started.
  
Qt S60 applications are easily built on Carbide IDE and they can be launched on S60 emulator or even on your device (you have to install Qt S60 libraries first). The entry point of any Qt application is the method main (remember that Android application starts from an Activity instance).
+
Qt Creator is an IDE built on Qt itself, and contains an easy-to-use visual designer for designing your application UI. An alternative to Qt Creator is Carbide++ IDE (based on the Eclipse framework). Both Qt Creator and Carbide C++ IDE provide a fully featured environment that helps a lot with development. You can find interesting articles on the Nokia Developer Wiki covering Qt (see [[:Category:Qt|Category Qt]]).
 +
 
 +
Qt applications are easily built with Qt Creator (included in Nokia Qt SDK) or Carbide IDE and they can be launched on the Qt Simulator, Symbian S60 emulator, or even on your device (you have to install Qt libraries first, however a properly packaged Qt application can do this automatically via [[Nokia Smart Installer for Symbian|Nokia Smart Installer]]). The entry point of any Qt application is the main method (remember that Android applications start from an Activity instance).
  
 
=== Examples ===
 
=== Examples ===
Line 67: Line 98:
 
</code>
 
</code>
  
As explained before, the entry point of any Android application is an Activity (more strict, the method android.app.Activity#onCreate(Bundle)). There's no label class on Android, but text view that can be also used as labels. Then, we create a text view and we set the contents of Activity with the text view just created.  
+
As explained before, the entry point of any Android application is an Activity (more strictly, the method android.app.Activity#onCreate(Bundle)). There's no label class on Android, but text views can be also used as labels. Then, we create a text view and we set the contents of Activity with the text view that was just created.  
  
Now, lets see how is the same application, but on Qt framework.
+
Now, let's see the same application, but on the Qt framework.
  
 
<code language="cpp-qt">
 
<code language="cpp-qt">
Line 85: Line 116:
  
  
It simply opens an application and shows a label with “Hello World” string. You can check that the main Qt class (QApplication) is properly intialized with the given arguments from main arguments. As described before, the entry point of Qt applications are the main function of your Qt main class. Then, it creates a simple label and show its content. Finally, the application return the code from execution of Qt application. Another important point is that such piece of code can also be built and launch on maemo platform (obviously, the graphical result is different, since you're using a different platform with different widgets).
+
It simply opens an application and shows a label with the “Hello World” string. You can check that the main Qt class (QApplication) is properly initialized with the given main method arguments. As described before, the entry point for Qt applications is the main function of your Qt main class. Then, it creates a simple label and shows its content. Finally, the application returns the code result from execution of the Qt application. Another important point is that such code can also be built and launched on the Maemo platform (obviously, the graphical result is different, since you're using a different platform with different widgets).
  
The following example shows how we can insert a menu on Android and Qt applications.
+
The following example shows how we can insert a menu with Android and Qt applications.
  
On Android, the menus are defined on method ''android.app.Activity#onCreateOptionsMenu(Menu)''. The callbacks of menu items are defined on method ''android.app.Activity#onOptionsItemSelected(MenuItem)''.
+
On Android, the menus are defined with the method ''android.app.Activity#onCreateOptionsMenu(Menu)''. The callbacks for menu items are defined with the method ''android.app.Activity#onOptionsItemSelected(MenuItem)''.
  
 
<code language="java">
 
<code language="java">
Line 133: Line 164:
 
</code>
 
</code>
  
On Qt S60, it is a little bit easier :). You just need to define a QtAction. Then, insert it on the application menu bar. Finally, the callback is defined on method ''connect'' (used to define any callback on Qt).
+
On Qt, it is a little bit easier :). You just need to define a QAction. Then, insert it onto the application menu bar. Finally, the callback is defined with the method ''connect'' (used to define any callback on Qt).
  
 
<code language="cpp-qt">
 
<code language="cpp-qt">
Line 164: Line 195:
 
* HTTP/FTP communication.
 
* HTTP/FTP communication.
 
** Android classes (from package '''java.net'''): HttpURLConnection, URL
 
** Android classes (from package '''java.net'''): HttpURLConnection, URL
** Qt classes: QHttp, QUrl, QUrlInfo
+
** Qt classes: QNetworkAccessManager, QUrl, QUrlInfo
 
** Android classes (from package '''org.apache.http.*'''): HttpClient, HttpGet, HttpPost, HttpResponse
 
** Android classes (from package '''org.apache.http.*'''): HttpClient, HttpGet, HttpPost, HttpResponse
 
** Qt classes: QHttpHeader, QHttpRequestHeader, QHttpResponseHeader
 
** Qt classes: QHttpHeader, QHttpRequestHeader, QHttpResponseHeader
** Qt class: QFtp (no correspondence with Android)
+
** Qt class: QFtp (no equivalent on Android)
  
 
==== Media ====
 
==== Media ====
Line 173: Line 204:
 
** Android classes (from package '''android.media'''): MediaPlayer, MediaRecorder
 
** Android classes (from package '''android.media'''): MediaPlayer, MediaRecorder
 
** Qt classes: AudioOutput, MediaController, MediaNode, MediaObject, MediaSource, ObjectDescription, Path, VideoPlayer
 
** Qt classes: AudioOutput, MediaController, MediaNode, MediaObject, MediaSource, ObjectDescription, Path, VideoPlayer
 +
 +
=== Android vs Qt ===
 +
Android was designed as a platform for mobile phones. Therefore, it provides access to different system resources, such as touch screen, camera, and telephony. On the other hand, Qt is a cross-platform application and UI framework designed for Desktop '''and''' Mobile environments. Qt provides mechanism to access resources of the mobile phone through [http://qt.nokia.com/products/qt-addons/mobility/ Qt Mobility APIs]. The following list shows some important differences of Android and Qt.
 +
 +
* Android provides access to '''PIM (Contacts, Calendar)''', Qt Mobility provides the [http://doc.qt.nokia.com/qtmobility-1.1.0/contacts.html Contacts API] and [http://doc.qt.nokia.com/qtmobility-1.1.0/organizer.html Organizer API] and [http://doc.qt.nokia.com/qtmobility-1.1.0/versit.html Versit API];
 +
* Android provides access to '''Telephony''', Qt Mobility provides [http://doc.qt.nokia.com/qtmobility-1.1.0/bearer-management.html Bearer Management API];
 +
* Android provides access to '''Messaging''', Qt Mobility provides the [http://doc.qt.nokia.com/qtmobility-1.1.0/messaging.html Messaging API];
 +
* Android provides access to '''Camera''', Qt Mobility provides [http://doc.qt.nokia.com/qtmobility-1.1.0/multimedia.html Multimedia API];
 +
* On Android, it is possible to load an application UI from an XML description file (Maemo also support this feature if you use Glade to build your application's UI). Qt provides two ways to design your application UI: [http://doc.trolltech.com/qtcreator-2.0/ Form Designer in Qt Creator] for designing application user interfaces, and [http://qt.nokia.com/qtquick/ QML of Qt Quick] for fluid interaction with animations.
 +
* Android is based on Java and Qt is based on C++;
 +
* Android applications are restricted to the Android platform, while Qt is cross-platform. A properly designed Qt application can be executed on Symbian, Maemo, and MeeGo mobile devices, and also on Windows, Linux, and Mac OS desktop platforms.
 +
  
 
=== References ===
 
=== References ===
  
 
*Qt
 
*Qt
**[http://www.qtsoftware.com/ Qt Site]
+
**[http://qt.nokia.com/ Qt.nokia.com]
**[http://www.forum.nokia.com/info/sw.nokia.com/id/c41e7898-2dd8-4f23-a629-d27727519ffa/Qt_for_S60_Developers_Library.html Qt for S60 Developer's Library]
+
**[http://doc.qt.nokia.com/ Qt reference documentation]
 
**[http://www.amazon.com/Foundations-Development-Experts-Voice-Source/dp/1590598318/ref=sr_1_1?ie=UTF8&s=books&qid=1241325621&sr=8-1 Foundations of Qt® Development (Book)]
 
**[http://www.amazon.com/Foundations-Development-Experts-Voice-Source/dp/1590598318/ref=sr_1_1?ie=UTF8&s=books&qid=1241325621&sr=8-1 Foundations of Qt® Development (Book)]
 
**[http://www.amazon.com/Programming-Prentice-Source-Software-Development/dp/0132354160/ref=sr_1_2?ie=UTF8&s=books&qid=1241325621&sr=8-2 C++ GUI Programming with Qt 4 (Book)]
 
**[http://www.amazon.com/Programming-Prentice-Source-Software-Development/dp/0132354160/ref=sr_1_2?ie=UTF8&s=books&qid=1241325621&sr=8-2 C++ GUI Programming with Qt 4 (Book)]
Line 188: Line 231:
 
**[http://developer.android.com/guide/index.html Developers Guide]
 
**[http://developer.android.com/guide/index.html Developers Guide]
 
**[http://www.amazon.com/Professional-Android-Application-Development-Programmer/dp/0470344717/ref=sr_1_1?ie=UTF8&s=books&qid=1241325308&sr=8-1 Professional Android Application Development (Book)]
 
**[http://www.amazon.com/Professional-Android-Application-Development-Programmer/dp/0470344717/ref=sr_1_1?ie=UTF8&s=books&qid=1241325308&sr=8-1 Professional Android Application Development (Book)]
 +
<!-- Translation --> [[zh-hans:向Qt for Symbian移植Android(Java)应用]]

Latest revision as of 08:28, 18 September 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

This article is somewhat old, and though mostly valid, inaccurate at places. More recent porting from Android to Qt documentation is available as part of the Porting to Qt Library

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: jaaura (07 Apr 2009)
Last edited: hamishwillee (18 Sep 2012)


Contents

[edit] Introduction

As an initiative of The Open Handset Alliance and Google, Android has been developed as the first open and free platform for mobile phones. The project has been developed since November 5, 2007, when Google Inc., Intel, T-Mobile, Sprint, HTC, Qualcomm and Motorola decided to achieve an ambitious goal: provide services so consumers would face a far better user experience.

An important point of the Android platform is that handset manufacturers and wireless operators can provide suitable versions of Android for their products and services. This characteristic directly impacts on lower cost and innovative products. Therefore, Android can be considered a new and potential option for mobile platforms for smartphones.

Android.jpgNokia-n97-2.jpg

On the other hand, Qt has been considered a powerful component in this newest mobile programming arena. Qt is most notably used in Desktop applications, such as KDE, Opera, Skype and VirtualBox, but recently it has been ported to Nokia mobile platforms, such as S60 and Maemo. Initially developed by Trolltech since 1991, Qt is released with two different licenses (open source and commercial), which should make Qt more suitable for non-GPL open source projects and for commercial users. In June 2008, Nokia acquired Trolltech to enable the acceleration of cross-platform software strategy for mobile devices and desktop applications. On September 29, 2008 Nokia renamed Trolltech to Qt.

This article provides information that guides development to port Android applications to Qt.

[edit] Overview of Android Platform

Android applications are developed with the Java programming language (Dalvik virtual machine), and device services, such as touchscreen and storage features, can be accessed through the Google services API. It is possible to run applications written in C or any other language, but the applications have to be compiled to native code and run; this development path is not officially supported by Google.

Since October 2008, Android has been available as an open source project (Apache License). Handset manufacturers and wireless operators are free do add closed and proprietary extensions to their products.

Although Android is based on a Linux kernel, according to Google, it is not a Linux operating system. In addition, it does not have a native windowing system, nor does it support the full set of standard Linux libraries, including the GNU C Library. This characteristic make it difficult to reuse existing Linux applications or libraries. Android does not use standard Java APIs, such as J2SE and J2ME. This prevents compatibility between Java applications written for those platforms and those for the Android platform. Android only reuses the Java language syntax, but does not provide the full-class libraries and APIs bundled with J2SE or J2ME.

The next picture shows the current Android architecture (from the Android Developer's Guide).

Android-architecture.jpg

The system has access to mobile phone resources through system drivers, such as camera, display, WiFi and keypad drivers. Then, the next layer consists of libraries and the runtime system of Android. Finally, Android provides a set of libraries (Application Framework) so it is possible to extend them and create new applications.

Android makes it possible to reuse components of other applications. For example, if you need to reuse a component that provides a suitable scroller and made it available to others, you can invoke such a component to do the work for you. Therefore, the system has been designed to start an application process when any part of it is needed, and instantiate the Java objects for that part. Therefore, Android does not provide an entry point, such as main function, but essential components: activity, services, broadcast receives and content providers.

Activities represent screens on an Android application. From an activity, you can display buttons, labels, menus and much more. All activities subclass the android.app.Activity class. Services do not have visual appearance, but they run in the background. For example, a service may play music while the user performs other tasks. Each service extends the android.app.Service base class. Broadcast receives are components that receive and react to different broadcast announcements, for example, a message that the battery is low. All receivers extend the android.content.BroadcastReceive base class. A content provider is responsible for making an application's data available to other applications. Therefore with content providers, it is possible to share data between different applications. All content providers extend the android.content.ContentProvider base class.

The Android development environment consists of: the Android SDK, Android source code and, optionally, IDEs that help make programming Android applications a lot quicker. The Android software development kit (SDK) consists of libraries and tools, including an emulator to run applications. The Android SDK is available for Windows, Mac OS X, and Linux. There are different IDEs that provide support for Android development, such as Eclipse (with the Eclipse plug-in for Android).

[edit] Overview of Qt

Qt applications are developed with C++ enhanced with additional extensions implemented by a pre-processor that generates standard C++ code before compilation. Qt also provides bindings for several other programming languages, like Python, Ruby and Perl.

Qts60.jpg

Qt is notably used because of its GUI widgets, but also provides a set of non-GUI related features: SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling. Qt has been successfully ported to the Nokia Symbian S60, Maemo, and MeeGo platforms. Qt will “enable you to create advanced applications with innovative user experiences while getting to market quickly”. Compared with Android, Qt is an interesting and easy-to-use programming framework that certainly brings a considerable contribution to mobile programming as well as desktop application development.

Qt-architecture.png

Qt Mobility has been completely ported to Symbian, and commonly used mobile features are accessible through the Qt Mobility APIs such as camera, geolocation, and contacts APIs. There are rapid on-going progress of making all mobile features accessible, and some features which are not provided by Qt Mobility APIs can still be accessed through native Symbian APIs.

In order to develop Qt Symbian applications, you simply need to install the Nokia Qt SDK, which contains Qt SDK, Qt Mobility SDK, Qt Creator, Qt Simulator for Symbian and N900, and libraries, tools (including the emulator for S60 environment), and all documentation you need to get started.

Qt Creator is an IDE built on Qt itself, and contains an easy-to-use visual designer for designing your application UI. An alternative to Qt Creator is Carbide++ IDE (based on the Eclipse framework). Both Qt Creator and Carbide C++ IDE provide a fully featured environment that helps a lot with development. You can find interesting articles on the Nokia Developer Wiki covering Qt (see Category Qt).

Qt applications are easily built with Qt Creator (included in Nokia Qt SDK) or Carbide IDE and they can be launched on the Qt Simulator, Symbian S60 emulator, or even on your device (you have to install Qt libraries first, however a properly packaged Qt application can do this automatically via Nokia Smart Installer). The entry point of any Qt application is the main method (remember that Android applications start from an Activity instance).

[edit] Examples

This is a simple “Hello World” application on Android.

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


package helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello World");
       setContentView(tv);
   }
}

As explained before, the entry point of any Android application is an Activity (more strictly, the method android.app.Activity#onCreate(Bundle)). There's no label class on Android, but text views can be also used as labels. Then, we create a text view and we set the contents of Activity with the text view that was just created.

Now, let's see the same application, but on the Qt framework.

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


#include <QApplication>
#include <QLabel>
 
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  QLabel label("Hello, world!");
  label.show();
  return app.exec();
}


It simply opens an application and shows a label with the “Hello World” string. You can check that the main Qt class (QApplication) is properly initialized with the given main method arguments. As described before, the entry point for Qt applications is the main function of your Qt main class. Then, it creates a simple label and shows its content. Finally, the application returns the code result from execution of the Qt application. Another important point is that such code can also be built and launched on the Maemo platform (obviously, the graphical result is different, since you're using a different platform with different widgets).

The following example shows how we can insert a menu with Android and Qt applications.

On Android, the menus are defined with the method android.app.Activity#onCreateOptionsMenu(Menu). The callbacks for menu items are defined with the method android.app.Activity#onOptionsItemSelected(MenuItem).

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


package helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Menu;
import android.widget.MenuItem;

public class HelloAndroid extends Activity {

   private final int MENU_QUIT = 1;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello World");
       setContentView(tv);
   }

   /* Creates the menu items */
   public boolean onCreateOptionsMenu(Menu menu) {
       menu.add(0, MENU_QUIT, 0, "Quit");
       return true;
   }

   /* Handles item selections */
   public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_QUIT:
        quit();
        return true;
    }
    return false;
   }

}

On Qt, it is a little bit easier :). You just need to define a QAction. Then, insert it onto the application menu bar. Finally, the callback is defined with the method connect (used to define any callback on Qt).

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


#include <QApplication>
#include <QAction>
 
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  QAction exitAction = new QAction(tr("&Exit"),this);

  // Add action direct to menubar
  menuBar()->addAction(exitAction);
  connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));
}

[edit] API Mappings

[edit] File I/O

  • To read from or write to files or other devices.
    • Android classes (from package java.io): File, FileReader, FileWriter, BufferedReader, BufferedWriter
    • Qt classes: QIODevice, QFile, QTemporaryFile, QBuffer, QProcess, QTcpSocket, QUdpSocket, QDataStream, QTextStream

[edit] Networking

  • Socket communication.
    • Android classes (from package java.net): Socket, InetSocketAddress, ServerSocket
    • Qt classes: QTcpSocket, QUdpSocket
  • HTTP/FTP communication.
    • Android classes (from package java.net): HttpURLConnection, URL
    • Qt classes: QNetworkAccessManager, QUrl, QUrlInfo
    • Android classes (from package org.apache.http.*): HttpClient, HttpGet, HttpPost, HttpResponse
    • Qt classes: QHttpHeader, QHttpRequestHeader, QHttpResponseHeader
    • Qt class: QFtp (no equivalent on Android)

[edit] Media

  • To read from or write to files or other devices.
    • Android classes (from package android.media): MediaPlayer, MediaRecorder
    • Qt classes: AudioOutput, MediaController, MediaNode, MediaObject, MediaSource, ObjectDescription, Path, VideoPlayer

[edit] Android vs Qt

Android was designed as a platform for mobile phones. Therefore, it provides access to different system resources, such as touch screen, camera, and telephony. On the other hand, Qt is a cross-platform application and UI framework designed for Desktop and Mobile environments. Qt provides mechanism to access resources of the mobile phone through Qt Mobility APIs. The following list shows some important differences of Android and Qt.

  • Android provides access to PIM (Contacts, Calendar), Qt Mobility provides the Contacts API and Organizer API and Versit API;
  • Android provides access to Telephony, Qt Mobility provides Bearer Management API;
  • Android provides access to Messaging, Qt Mobility provides the Messaging API;
  • Android provides access to Camera, Qt Mobility provides Multimedia API;
  • On Android, it is possible to load an application UI from an XML description file (Maemo also support this feature if you use Glade to build your application's UI). Qt provides two ways to design your application UI: Form Designer in Qt Creator for designing application user interfaces, and QML of Qt Quick for fluid interaction with animations.
  • Android is based on Java and Qt is based on C++;
  • Android applications are restricted to the Android platform, while Qt is cross-platform. A properly designed Qt application can be executed on Symbian, Maemo, and MeeGo mobile devices, and also on Windows, Linux, and Mac OS desktop platforms.


[edit] References

This page was last modified on 18 September 2012, at 08:28.
304 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×