Using Qt classes natively in an Android application - qt

The Android application I am about to work on has the UI in Java and the non-UI functionality in C++ that would be accessed via JNI. The C++ code uses some non-UI Qt classes. I am thinking I will spawn a thread in JNI_OnLoadthat essentially will instantiate and run QCoreApplication. Any subsequent JNI call will simply post an event to this thread. Is this possible? Regards.

What you want to do is definitely possible but a bit more difficult than it seems initially.
If you build your app end to end in Qt there's a lot of functionality you get for free from their framework that allows it to run on Android and a lot of that functionality/plumbing is wrapped up in their UI. So if you're not using their UI there's extra work that you need to do.
On Android their UI framework basically creates a native Activity and then uses that activity as a wrapper for the app. If you look at the low-level source for their UI thats what's happening on Android and it's what allows the Qt app to access local resources, the network, OS facilities, etc.
Without the Activity wrapper, your app will only be able to do simple, in-memory operations that require no OS, file system, or network access and also won't be able to make use of other Qt libraries(eg Qt5Sql, Qt5Core, etc).
Here's what we had to do to make this work in our java app:
Create a proxy wrapper Activity for Qt to use that shares the base
context of your app.
Create a QtActivityDelegate.
Set the proxy activity and delegate using the native Qt android
libraries. eg QtNavite.setActivity.
Instantiate and set a DexClassLoader using the same native Qt android libraries.
Load any Qt libraries using System.loadLibrary(..). Please note that the libraries need to be present on the file system already. This part was a big pain for us.
For your Qt Code, make sure you have proper wrappers written so that they can be used via jni. We ended up using swig to auto-generate java wrappers for our code.
You can find out more about swig here: http://swig.org/
After all that you should be able to use your Qt class/library from within a native Android app.
Painful but definitely possible!

Related

How to use qt webassembly in qml application

I am beginner in web assenbly and I want to use qt webassembly in qml application. I use emsdk 1.38.30-64bit to compile qml application and it compile successfully but when I use emsdk 1.38.30-64bit with thread flag in my browser I get downloading/compiling. what is my mistake and how should I solve this problem?
Qt multi-thread support is still quite in development, a single thread application should be in general fine for QML apps, the QML engine is still single threaded. Try also newer emscripten compilers, but even in my extensive testing with versions 1.39+ multi-thread was an issue. Quick note if you want to test your QML app in the browser, you can use Felgo WebEditor for quick snippet testing https://felgo.com/web-editor or you can test our fully fledged web IDE https://ide.felgo.com

How notify user when my application is not running in qt?

I have a qt quick 2 application that I run it in android.Now I want to show message to my users ,For example I want to send a get Request to my server to find out "Is this user has any message from another user or not?" and if has new message show a notification to my user.This should be run when my application is not runnng.
But I didn't see any Class that i can do this in qt?
How can I Do this?
Qt for Android lists what you can do with Qt. Qt Android Extras includes classes that wrap the most important functions of few Android package methods, but is not intended to provide out of the box methods for everything in Android.
You can write Java Classes to implement detailed or specialized Android functions, those then can easily be implemented with Qt using the rich Android Extras JNI APIs.
In Qt Examples, Qt Notifier, serves very similar or same functionality you asking for.
You can run Android services (long running apps hiding user interface) , by Creating Android Services And QAndroidService Class

How to access the QObject of a Qt UI from another QT application?

I am intending to implement a simple test QT application in linux which launch a QT UI application running on an Embedded linux platform to verify it. I want to be able to send signals from the test application to the UI, for instance to press a button on the GUI, then check if the signal has made the expected change on the QT UI application. I know there are some tools like Squish, Testability Driver that can hook a running QT application and access the properties of each graphical element (e.g. button).
I have searched a lot, but I could not find any suitable solution. If somebody can introduce a suitable solution?
On Unix platforms you can use dbus. Otherwise you have to roll your own mechanism, or use a third party tool.

Modify Qt's shared library code while application starts

I'm trying to create some kind of a server which allows me to start Qt's applications on remote machine via web browser.
I'm wondering it is possible to change/hide some symbols from Qt library (I thought about QApplication or QCoreApplication) without making any changes in code of application (I assume that it is already compiled and uses Qt shared library) and compiling my whole tailor-made Qt libs?
The reason why I need to do this is because I want to install my own specific EventFilter to QApplication and also be able to push my own created events to Qt application.
It also would be great if the solution could be used on all platforms :D
P.S. I know that it will not be possible I could subclass QApplication and modify all Qt apps to use my derived class but I would like to do this more craftily. ;-)
The tool GammaRay does all kinds of injecting code into Qt methods at runtime to attach and debug running Qt applications. You might want to have a look at its code base to see how it is done.

Make a phone call with qt 4.6.3

I need to trigger a phone call from a Qt application. I looked to previous post without find a complete answer.
I need to make it with qt 4.6.3. I'm quite new to symbian development, I'm using the last nokiaSDK.
It MUST work ONLY on n97 and E71.
Can Anybody provide a solution?
May be a solution exec an extenal process using QProcess?
It seems like currently none of Qt APIs (including QtMobility) allows to do it. However, you can use native Symbian C++ API - CTelephony class. There are some examples showing how to make a phone call using this class. The obvious disadvantage is that it won't work on any other platform than Symbian.
You may be interested in this example: http://library.forum.nokia.com/topic/Qt_for_Symbian_Developers_Library/GUID-B4DA6005-3037-4FF8-82D5-BA748532E648.html#GUID-B4DA6005-3037-4FF8-82D5-BA748532E648. It shows how to mix Symbian C++ code with Qt code, and it also uses CTelephony, so you just need to change method call from GetPhoneId() to DialNewCall(). Don't forget to add appropriate library (etel3rdparty.lib) in your .pro file.

Resources