I am trying to store recorded values from sensors to a ".txt" file, I have narrowed the error to the for-loop where I write the values to the ".txt" file but I have no idea what the error is, please help
- getsamples: sends the values to be saved to datalogger
- datalogger saves the lead values to the txt file but crashes in the for loop
- ecgstorestructure is the structure that holds the sensor information and time, it indicates the format that variables are saved in
The code can successfully create the txt file but it crashes as soon as I try use the forloop to write the lead values into the txt file
getsamples.cpp
#include "getsamples.h"
#include <QVector>
#include <QPointF>
#include <QDebug>
#include <QFile>
#include <QSettings>
#include <QCoreApplication>
#include <QtMath>
#include "ecgstorestructure.h"
#include "getsamples.h"
#include "datalogger.h"
void getsamples::sample(double elapsed, DataStream& inputStream)
{
DataLogger logger;
// qDebug() << ("getsamples: sample") << endl;
//Frame Format:
// Elapsed (ms) | Lead 1 | Lead 2 | Lead 3 | Respiration | Lead off detection
// Lead off: 1 = leads disconnected, 0 = leads connected
QVector<double> frame;
frame.append (elapsed);
frame << ecg-> readFrame();
static double lead1, lead2, lead3, respiration;
lead1 +=frame.at(1);
lead2 +=frame.at(2);
lead3 +=frame.at(3);
respiration += frame.at(4);
inputStream.append(EcgStoreStructure(frame.at(1), frame.at(2), frame.at(3), frame.at(4), elapsed/1000));
logger.save(inputStream);
#include "getsamples.h"
#include <QVector>
#include <QPointF>
#include <QDebug>
#include <QFile>
#include <QSettings>
#include <QCoreApplication>
#include <QtMath>
#include "ecgstorestructure.h"
#include "getsamples.h"
#include "datalogger.h"
void getsamples::sample(double elapsed, DataStream& inputStream)
{
DataLogger logger;
// qDebug() << ("getsamples: sample") << endl;
//Frame Format:
// Elapsed (ms) | Lead 1 | Lead 2 | Lead 3 | Respiration | Lead off detection
// Lead off: 1 = leads disconnected, 0 = leads connected
QVector<double> frame;
frame.append (elapsed);
frame << ecg-> readFrame();
static double lead1, lead2, lead3, respiration;
lead1 +=frame.at(1);
lead2 +=frame.at(2);
lead3 +=frame.at(3);
respiration += frame.at(4);
inputStream.append(EcgStoreStructure(frame.at(1), frame.at(2), frame.at(3), frame.at(4), elapsed/1000));
logger.save(inputStream);
To copy to clipboard, switch view to plain text mode
datalogger.cpp
#include "datalogger.h"
#include "settingssingleton.h"
#include <QDebug>
#include <iostream>
#include "ecgstorestructure.h"
#include <QFile>
#include <QTextStream>
void DataLogger::saveAsText(DataStream &input){
QString mFilename2
= SettingsSingleton
::instance().
getFileName()+".txt";
QFile outFile
(mFilename2
);
{
qDebug()<< "could not open file for writing";
return;
}
for (int i ; i<input.size();i++){
// ERROR OCCURS HERE
const EcgStoreStructure tmp=input.at(i);
out2 << tmp.toText() << endl; //"\n";
}
outFile.close();
#include "datalogger.h"
#include "settingssingleton.h"
#include <QDebug>
#include <iostream>
#include "ecgstorestructure.h"
#include <QFile>
#include <QTextStream>
void DataLogger::saveAsText(DataStream &input){
QString mFilename2 = SettingsSingleton::instance().getFileName()+".txt";
QFile outFile(mFilename2);
if(!outFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug()<< "could not open file for writing";
return;
}
QTextStream out2(&outFile);
for (int i ; i<input.size();i++){
// ERROR OCCURS HERE
const EcgStoreStructure tmp=input.at(i);
out2 << tmp.toText() << endl; //"\n";
}
outFile.close();
To copy to clipboard, switch view to plain text mode
ecgstorestructure.cpp
#include "ecgstorestructure.h"
EcgStoreStructure::EcgStoreStructure()
{
}
EcgStoreStructure::EcgStoreStructure(double _frame1, double _frame2, double _frame3, double _resp, double _time): frame1(_frame1), frame2(_frame2),frame3(_frame3),time(_time),resp(_resp){
}
QString EcgStoreStructure
::toText() const {
return tmp;
}
EcgStoreStructure::~EcgStoreStructure(){
}
#include "ecgstorestructure.h"
EcgStoreStructure::EcgStoreStructure()
{
}
EcgStoreStructure::EcgStoreStructure(double _frame1, double _frame2, double _frame3, double _resp, double _time): frame1(_frame1), frame2(_frame2),frame3(_frame3),time(_time),resp(_resp){
}
QString EcgStoreStructure::toText() const {
QString tmp = QString::number(time) + "\t" + QString::number(frame1) + "\t"
+ QString::number(frame2) + "\t" + QString::number(frame3) + "\t"
+ QString::number(resp);
return tmp;
}
EcgStoreStructure::~EcgStoreStructure(){
}
To copy to clipboard, switch view to plain text mode
datastream.cpp
#include "datastream.h"
DataStream::DataStream(){
}
DataStream::~DataStream(){
}
QString DataStream
::toText(int index
){ return this->at(index).toText();
}
#include "datastream.h"
DataStream::DataStream(){
}
DataStream::~DataStream(){
}
QString DataStream::toText(int index){
return this->at(index).toText();
}
To copy to clipboard, switch view to plain text mode
Bookmarks