c++ - Qt reading file and mapping to QVector very slow (crashes) -
so trying read file , map 2 dimensional qvector. here code far
void datamodel::parsefilebylines() { qvector<qvector<qstring> > dataset; lasterror = ""; qregexp reg(filedelimiter); qfile infile(inputfile); if (infile.open(qiodevice::readonly)){ qtextstream fread(&infile); long totalsize = infile.size(); qstring line; while(!fread.atend()){ line = fread.readline(); dataset.append(line.split(reg,qstring::keepemptyparts).tovector()); } }else{ lasterror = "could not open "+inputfile+" reading"; } }
my issue when dealing 1000,000 lines or more program crashes message saying "this application has requested runtime terminate in unusual way". there more efficient way can achieve goal ? if how ?
the input file may in format so
id,name,age,gender...etc
1,sam,12
...
...
1000000
i appreciate or advice
i have tested (qlist) version here on computer , runs faster qvector version , believe not crash.
void parsefilebylines(qstring inputfile) { qlist<qlist<qstring> > dataset; qstring lasterror = ""; qfile infile(inputfile); if (infile.open(qiodevice::readonly)){ qtextstream fread(&infile); long totalsize = infile.size(); qstring line; while(!fread.atend()){ line = fread.readline(); qlist<qstring> record = line.split('\t',qstring::keepemptyparts); dataset.append(record); } }else{ lasterror = "could not open "+inputfile+" reading"; } }
Comments
Post a Comment