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