From 31a0592f40ccbe0ed31abcd8bf39c2c00dab699a Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Mon, 6 Feb 2023 22:54:40 +0000 Subject: try to fix file overwriting instead of appending --- sensors.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sensors.cpp b/sensors.cpp index df87122..ac286c1 100644 --- a/sensors.cpp +++ b/sensors.cpp @@ -81,19 +81,20 @@ void Logger::setupRecordHeartrate() { } void Logger::recordHeartrate() { + qDebug() << "bpm update received"; int bpm = heartrateSensor->reading()->bpm(); qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << bpm << heartrateSensor->status() << heartrateSensor->isActive(); if ((bpm == 0) || (heartrateSensor->status() < 3)) { return; } QFile file("out.txt"); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { qDebug() << "failed to open file"; return; } + file.seek(file.size()); QTextStream out(&file); - while(!out.atEnd()){} - out << QDateTime::currentSecsSinceEpoch() << " : " << bpm; + out << QDateTime::currentSecsSinceEpoch() << " : " << bpm << "\n"; qDebug() << "wrote to file"; heartrateSensor->stop(); file.close(); -- cgit v1.2.3-70-g09d2