Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting of Qt code on Android and how it works

I was thinking of porting my Qt application on android.

My question is how a code written in C++ and Qt which is also a C++ library gets ported to android as android requires java code and an apk file is needed to install the app on device. I am curious as to how and what things they do on the code to make it work like a java code.

If the question is not clear , please comment and i will do my best to make it more clear.

like image 583
Rahul Assassin Avatar asked Jan 13 '15 05:01

Rahul Assassin


1 Answers

Android applications are Java applications, running on a virtual machine called “Dalvik”. This causes many challenges for a Qt/C++ application to run on such a Java based platform. To ovecome this, a Qt for Android application has two parts. The first part is your Qt/C++ native application which is organized by qmake. The second part is a launcher which is a Java code generated by Qt Creator automatically based on your application preferences, settings and target Android version.

The launcher is a Java process, so Qt Android applications have a Java-based entry point. The Java code in launcher will load the required Qt libraries, based on the meta-information given in other files in the template. So when a Qt for Android application is started, it's just a regular Java application. The entry point will be in QtActivity.java which can be found under android/src/… in your project build directory.

After loading the Qt libraries, the Java code will start the application's native main() function on a new thread and the application will launch. At this point, the Java code is used to delegate events from Android into Qt. Qt for Android applications use "Java Native Interface" (JNI) to communicate between Java world and C++ world.

like image 68
Nejat Avatar answered Sep 28 '22 01:09

Nejat