Porting Qt code on Android and using it

I was thinking about porting my Qt application to Android.

My question is how code written in C ++ and Qt, which is also a C ++ library, is ported to android, since the android requires Java code, and the apk file is needed to install the application on the device. I'm curious how and what they do in the code so that it works like Java code.

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

+5
source share
2 answers

Android applications are Java applications running on a virtual machine called "Dalvik". This causes many problems for a Qt / C ++ application to run on such a Java-based platform. To do this, the Qt Android app has two parts. The first part is your own Qt / C ++ application, which is hosted by qmake. The second part is the launcher, which is the Java code created by Qt Creator, automatically based on your settings, settings and the target version of Android.

Launcher is a Java process, so Qt apps for Android have a Java-based entry point. The Java code in Launcher will load the necessary Qt libraries based on the meta-information specified in other files in the template. Therefore, when the Qt application for Android is launched, it is just a normal Java application. The entry point will be in QtActivity.java , which can be found in android/src/… in the project build directory.

After loading the Qt libraries, the Java code will run the main () function of the application in a new thread, and the application will start. At this point, Java code is used to delegate events from Android to Qt. Qt for Android applications uses the Java Native Interface (JNI) to communicate between the Java world and the C ++ world.

+4
source

Just use Qt5.4.0 and install the NDK + android SDK, it will be very easy for you that you can use C ++ on Android.

0
source

Source: https://habr.com/ru/post/1210952/


All Articles