Important: Please read the Qt Code of Conduct -

Emit is not working when calling on a separate android thread

  • Hey. Sorry for my english.

    There is a code that running on android on a separate Thread (Java Code) like this:

    public class ClientThread extends Thread
    public void run()
    MainActivity.nativeMethod(); // not working

    public class MainActivity extends QtActivity
    private static final String TAG = "MainActivity";
    private static MainActivity _instance = null;
    private static ClientThread _clientThread = null;

    public MainActivity()
        _instance = this;
    public void onCreate(Bundle savedInstanceState)
        nativeMethod(); // working
        _clientThread = new ClientThread();
    public static native void nativeMethod();


    And there is C++ bridge for that:

    @class TestObject : public QObject

    explicit TestObject(QObject *parent = 0);
    static TestObject *getInstance();

    void nativeMethod();

    public Q_SLOTS:


    static void jniNativeMethod(JNIEnv *, jclass)
    qDebug() << "works threaded or non-threaded calls"
    emit TestObject::getInstance()->nativeMethod();

    Also a QML connection:

    @import TestObjectPackage 1.0

    target: TestObjectPackage.testObjectInstance
    console.log("QML received signal!");

    jniNativeMethod calls every time but emit not sending signal to QML on sepearate thread. Could you help me?

  • I wonder if the problem is due to the use of a static signal.

    Cross-thread signal delivery uses an event loop in the receiving thread. Intra-thread delivery is a direct call by default. The static use might confuse the detection of the correct connection type.

Log in to reply