Search code examples
androidc++qtqmlqtandroidextras

QML on android - will C++ work for business logic?


Doing some investigation on the feasibility of using QT/QML for an upcoming project. Client wants it initially on Windows and Mac desktops, with the possibility of iOS and Android down the road. They would like to know that what we build will move relatively easily. I'm not much of a desktop programmer, but what I see is that QML is designed to work with C++. As a result, it should be relatively easy to build an app that runs on Mac and Windows, and iOS will accept C++, so I can't see a lot of roadblocks there. But I'm confused about Android. I see folks talking about building an Android app using QML, but they seem to still be using java; I gather it uses the NDK in the background.

But if you write an application that has QML for the front and, and C++ for any guts not covered by QML, can it work on Android? Or do you need to rewrite the C++ piece in java? The app is not a simple one, so we are going to have to provide some logic outside of QML, at least, it sure looks that way. While we might save time and $$$ by using QT to not have to go native on the desktops and iOS, I see a problem with Android down the road.


Solution

  • But if you write an application that has QML for the front and, and C++ for any guts not covered by QML, can it work on Android? Or do you need to rewrite the C++ piece in java?

    It really depends. You may need to go through the Java interface where the Android platform does not provide direct and public API for certain functionality. One example is low-level IO operations, like writing the serial port for usb-serial devices, but there is more to it.

    In general, what Qt modules and third-party software based on Qt do is to use the QAndroidExtras add-on module introduced in Qt 5.2. This will allow easy backend integration into your C++ logic.

    With that in mind, you could hide the Java implementation details in the background while you still maintain the C++ interface to QML. Therefore, it should just work that way.

    Please see the following documentation to get the grasp of it:

    Qt Android Extras

    Here you can find one of those nice examples:

    Qt Notifier - Demonstrates calling Java code from an Android application.