-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilerwkit.cpp
More file actions
51 lines (47 loc) · 1.35 KB
/
filerwkit.cpp
File metadata and controls
51 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "filerwkit.h"
QFileIO::QFileIO(QObject *parent) :
QObject(parent)
{
}
QVector< QVector<double> > QFileIO::ReadCSV(QString filename)
{
QFile file(filename);
QString lineend="";
QVector< QVector<double> > vectors(1);
int numlines=0;
if (file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
QString line = in.readAll(); //read one line at a time
QStringList strings1 = line.split("\n");
QStringList strings2 = line.split("\r");
QStringList strings3 = line.split("\r\n");
QStringList strings;
if(strings3.length()>1){
numlines=strings3.length();
lineend="\r\n";
strings=strings3;
}else
if(strings1.length()>1){
numlines=strings1.length();
lineend="\n";
strings=strings1;
}else
if(strings2.length()>1){
numlines=strings2.length();
lineend="\r";
strings=strings2;
}
vectors.resize(numlines);
for(int i=0;i<numlines;i++){
QStringList splitline = strings.at(i).split(",");
QVector<double> a(splitline.length());
for(int j=0;j<splitline.length();j++){
a[j]=splitline[j].toDouble();
}
vectors[i]=a;
}
}
file.close();
return vectors;
}