Even though user vahanchos answer was helpful for me, and probably is the way to go for others, I ended up with a different solution.
In my case I code for only one special device type and a known set of development machines. therefore I could just read the relevant files in sys/class/power_supply/
. I can not guarantee that other devices will name their files there exactly the same. But it might be worth the try.
#include <QFile>
void refreshValues(){
QFile acLine("/sys/class/power_supply/AC/online");
QFile acAdp("/sys/class/power_supply/ADP0/online");
QFile bCap("/sys/class/power_supply/BAT0/capacity");
bool ac = false;
int level = 0;
if(acLine.exists()){
acLine.open(QIODevice::ReadOnly | QIODevice::Text);
if(QString(acLine.readAll()).toInt()){
ac = true;
}
acLine.close();
}else if(acAdp.exists()){
acAdp.open(QIODevice::ReadOnly | QIODevice::Text);
if(QString(acAdp.readAll()).toInt()){
ac = true;
}
acAdp.close();
}
if(bCap.exists()){
bCap.open(QIODevice::ReadOnly | QIODevice::Text);
level = QString(bCap.readAll()).toInt();
bCap.close();
}
setAcPowerActive(ac);
setBatteryLevel(level);
}