In the qt main thread I successfully can run this:
jbyteArray jBuffer = _env->NewByteArray(bufferSize);
The _env
is a QAndroidJniEnvironment
. but If I try to use _env
in the run function of a QRunnable
, the application crashes and this error occurs:
Fatal signal 11 (SIGSEGV), code 1
This is the code:
class HelloWorldTask : public QRunnable
{
QAndroidJniEnvironment * _env;
void run()
{
qDebug() << "Hello world from thread" << QThread::currentThread();
jbyteArray jBuffer = (*_env)->NewByteArray(10);
qDebug() << "Hello 2 world from thread" << QThread::currentThread();
}
public:
void setPointer(QAndroidJniEnvironment * p){
_env = p;
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
HelloWorldTask * hello = new HelloWorldTask();
QAndroidJniEnvironment env;
QAndroidJniEnvironment * p = & env;
hello->setPointer(p);
QThreadPool::globalInstance()->start(hello);
return a.exec();
}
Could you please tell me how can I use the pointer to the QAndroidJniEnvironment
or QAndroidJniObject
in a new Qthread? so the application ui remains responsive during the execution of java process.