Skip to content
  • 144k Topics
    722k Posts
    SMF-QtS
    I have a java file (QtBattery.java) import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; public class QtBattery { public double getBatteryPercentage(Context context) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); if (batteryStatus != null) { int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if (level != -1 && scale != -1) { return ((level * 100.0)/ scale); } } return -1.0; // Return -1.0f if battery status cannot be retrieved } } A c++ method in a QWidget class that periodically is called to check the Android battery status. #ifdef ANDROID jdouble QtTest4::batteryStatus() { jdouble batteryLevel=-1.0; QJniObject activity = QNativeInterface::QAndroidApplication::context(); if (activity.isValid()) { QJniObject context = activity.callObjectMethod("getApplicationContext", "()Landroid/content/Context;"); if (context.isValid()) { batteryLevel = context.callMethod<jdouble>("com/home/QtTest4/QtBattery", "getBatteryPercentage"); } } return batteryLevel; } #endif The AndroidManifest.xml includes: <uses-permission android:name="android.permission.BATTERY_STATS"/> The problem is the batteryLevel variable is always returned as zero (0.0). I am looking for suggestions or ideas has to what is wrong. Thanks.
  • Jobs, project showcases, announcements - anything that isn't directly development
    4k 23k
    4k Topics
    23k Posts
    jeremy_kJ
    What update rate is being attempted? What does the general program structure look like?
  • Everything related to designing and design tools

    127 383
    127 Topics
    383 Posts
    R
    I see this is an old thread and I see several unresolved threads on this topic. I'm leaving this incase it helps someone else who ends up here. The solution was twofold for me. Go to File > Export Project and select Enable Python Generator. This will create a main.py. Make sure you pip install PySide6-DS Hope this helps someone.
  • Everything related to the QA Tools

    77 213
    77 Topics
    213 Posts
    J
    Hello i am using WinCC OA to develop a qt application. WinCC OA has some custom elements which cannot be detected by squish for example a polygon. Squish is now not able to detect this element with the picker. I know the name of the element but as it is of WinCC OA internal i do not know the type: waitForObject( {"container": "container", "name": "POLYGON1","type": "???","visible": 1} ); How do i get this information? And what to use if unknown? Is there any other way? I mainly just need to click this element. Thanks a lot
  • Everything related to learning Qt.

    382 2k
    382 Topics
    2k Posts
    V
    Thank you 😊
  • 2k Topics
    13k Posts
    SGaistS
    Oh right, I forgot about that one. Depending on the content you can apply the same to rows. In any case, since your issue is fixed, please mark the thread as solved using the "Topic Tools" button so that other forum members may know a solution has been found :-)
  • 4k Topics
    18k Posts
    M
    @Max Ok, j'ai compris : en modifiant la taille de la fonte du QLineEdit inclus dans le QTimeEdit, ça fonctionne. Bêtement je prenais la police "f" du QLineEdit inclus, modifiais la taille de "f" et faisais QLineEdit->parent->setFont(f). Ici "parent" était de trop. En me relisant, j'espère que ce que j'ai écris est compréhensible... A+ Sylvain
  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k 10k
    1k Topics
    10k Posts
    SGaistS
    @RokeJulianLockhart to the best of my knowledge, no. The first release of Discourse was in 2014 and the forum is several years older than that.