Don't try to use non-existent files

This commit is contained in:
Matti Viljanen 2022-08-07 22:48:36 +03:00
parent 4c243e913d
commit 7603a6d161
No known key found for this signature in database
GPG key ID: CF32A1495158F888

View file

@ -205,7 +205,7 @@ Battery::~Battery() {
void Battery::updateData()
{
if(chargeFile->open(QIODevice::ReadOnly)) {
if(chargeFile && chargeFile->open(QIODevice::ReadOnly)) {
nextCharge = chargeFile->readLine().trimmed().toInt();
if(nextCharge != charge) {
charge = nextCharge;
@ -213,7 +213,8 @@ void Battery::updateData()
}
chargeFile->close();
}
if(chargerConnectedFile->open(QIODevice::ReadOnly)) {
if(chargerConnectedFile && chargerConnectedFile->open(QIODevice::ReadOnly)) {
nextChargerConnected = chargerConnectedFile->readLine().trimmed().toInt();
if(nextChargerConnected != chargerConnected) {
chargerConnected = nextChargerConnected;
@ -222,7 +223,7 @@ void Battery::updateData()
chargerConnectedFile->close();
}
if(currentFile->open(QIODevice::ReadOnly)) {
if(currentFile && currentFile->open(QIODevice::ReadOnly)) {
nextCurrent = currentFile->readLine().trimmed().toInt();
if(nextCurrent != current) {
current = nextCurrent;
@ -231,7 +232,7 @@ void Battery::updateData()
currentFile->close();
}
if(stateFile->open(QIODevice::ReadOnly)) {
if(stateFile && stateFile->open(QIODevice::ReadOnly)) {
nextState = (QString(stateFile->readLine().trimmed().toLower()));
if(nextState != state) {
state = nextState;