Skip to content Skip to sidebar Skip to footer

Java Executes But Not C++ In Qt 5.7 For Android (worked In Prior Qt)

I have an Android app written in Qt that has the same basic structure as the Qt Notifier example : http://doc.qt.io/qt-5/qtandroidextras-notification-example.html There is a native

Solution 1:

I can't believe that no else has had this same problem! At least I can't find anyone else reporting this.

I found that if the Java side QtActivity class calls setContentView() from onCreate(), then the C++ main function is never called! This was not an issue until this new version of Qt. Note that QtNotifier example I referenced in my question doesn't do that, why is why it runs on Qt 5.7 out of the box.

I had to revise my logic so that the Java QtActivity class does it other initialization tasks, but leaves out setContentView() to natively load the ui. Then the C++ fires off. From the C++ side, I issue a jni call to the QtActivity class which then uses setContentView(). Note that I have to use a static instance reference to the QtActivity class (which I assign in onCreate), and I have to run that code on the main/ui thread.

Here are some useful code snippets for you to drop into a Java QtActivity class:

privatestatic MyQtActivityClass instance_;
privatestatic Handler mainHandler_;

...

@OverridepublicvoidonCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    instance_ = this;
    context_ = this.getApplicationContext();
    mainHandler_ = newHandler( Looper.getMainLooper() );
}

publicstaticvoidrunOnMainThread( Runnable runnable ) {
    mainHandler_.post( runnable );
}

...

runOnMainThread( new Runnable() {
        publicvoidrun() {
            instance_.setContentView( R.layout.XXXXXX );
        }
    });

Post a Comment for "Java Executes But Not C++ In Qt 5.7 For Android (worked In Prior Qt)"