Menu
  • HOME
  • TAGS

How to keep the screen on in Qt for android?

java,android,c++,qt,qtandroidextras

You can use the Qt Android Extras module and use JNI to call the relevant Java function from C++. Something like : void keepScreenOn() { QAndroidJniObject activity = QtAndroid::androidActivity(); if (activity.isValid()) { QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); if (window.isValid()) { const int FLAG_KEEP_SCREEN_ON = 128; window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON); } }...

Sending jbyte array to Java method failed using JNI

c++,qt,jni,qtandroidextras,jbytearray

The signature for a type of jbyteArray is [B. So the method call should be like : jniObject.callMethod<jint>("write","([BI)I",buffer,1000); ...

error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*)'

android,c++,qt,linker-error,qtandroidextras

As it can be seen in the following table, the integer types are primitive, whereas the rest is object types. Therefore, I suggest that you try using instead: jstring b = QAndroidJniObject::callStaticMethodObject("HelloJava", "getString") This is not a bug, but feature. See the following issue tracker entry on the official stance:...

Qt does not compile callStaticObjectMethod() it says no matching function to call for

c++,qt,jni,qtandroidextras

Try: QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod( "org/.../TestClass" ,"staticMethod" ,"(Ljava/lang/String;)Ljava/lang/String;" ,val.object<jstring>()); I think this function doesn't take template parameter. Than you can do: str.toString() //returns QString And make sure you have imported the Java source files to your android build. For example if your java classes are under android-sources folder add this...

what are the usage of callStaticObjectMethod callStaticMethod

qt,qtandroidextras

As I've mentioned in a comment, the callStaticMethod is used with primitive types (which are listed here). This function returns the type you requested (ex. jint) not QAndroidJniObject. And callStaticObjectMethod is used with methods returning an object type (which are listed here). It returns the QAndroidJniObject. You can find example...

Convert jstring to QString

android,c++,qt,qstring,qtandroidextras

You need to use this method. QString QAndroidJniObject::toString() const Returns a QString with a string representation of the java object. Calling this function on a Java String object is a convenient way of getting the actual string data. So, I would write this if I were you: QAndroidJniObject string =...

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

android,c++,qt,qml,qtandroidextras

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...

Calling simple java static method via JNI does not work, though c++ compiles and run it

android,c++,qt,jni,qtandroidextras

You should specify the returned JNI type in <...> when calling the method : QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod<jstring>( "org/.../TestClass" ,"staticMethod"); QString string = str.toString(); Here there is no need to define the signature since your function has no argument....

How to use QAndroidJniEnvironment pointer in a Qthread?

qt,qthread,qtandroidextras

Only 15 people have read this question so far. And still no answer. My be it's a very hard or very easy question to answer!! Anyway I found the solution with the help of qt forum users. Here is the working code: class HelloWorldTask : public QRunnable { QAndroidJniEnvironment *...

What is the difference between QAndroidJniObject::callMethod() and QAndroidJniObject::callObjectMethod()?

android,c++,qt,qt5,qtandroidextras

The main difference is that QAndroidJniObject::callMethod returns a primitive data type like jint or jbyte but QAndroidJniObject::callObjectMethod returns an object of type QAndroidJniObject. Using which one all depends on your needs and the return type of the function you want to call. If your function returns an object type like...