我的应用程序在Qt我目前正在尝试读取一个非常大的格式化文本文件(20.000.000行)并在一些QStringLists(复数)中收集数据。
每行生成4个QStringList组件,每个组件包含10个字符。
总是在同一点上,应用程序崩溃了" Runtume错误!"。
我说的是同一点,因为如果我尝试删除最后一行读取,我会在下一行收到错误。 (我正在谈论在第16.000.000行崩溃)
我不确定(也不太熟练......),但我认为我有点达到记忆能力,可能是这样吗?这样做是否有一些解决方法或更好的方法?
这是我从文本文件中收集数据的代码的一部分:
int lcCount=0;
QStringList loadcase, elid, plyid, eltyp, sigmax, sigmay, sigmaz, sigmaxy, sigmaxz, sigmayz;
QString currentLC, currentELtyp;
QStringList status; status<<"LCoff"<<"ELoff"<<"PLYoff";
QStringList lineList;
while(!in.atEnd())
{
//PROGRESS BAR
int pBarValue = countRow*100/countTotRow;
//qDebug()<<countRow<<" - " << countTotRow;
m_pBar->avanzamentoPCH(pBarValue);
qApp->processEvents();
QString line = in.readLine(); countRow++;
if(line.contains("$TITLE")){status.replace(0,"LCoff");status.replace(1,"ELoff");}
if (line.contains("$SUBCASE ID ="))
{
status.replace(0,"LCon");
line.chop(30);
line.remove(" ");
line.remove("$SUBCASEID=");
currentLC = line;
lcCount++;
} else if (line.contains("$ELEMENT TYPE =") && status.at(0)=="LCon")
{
line.chop(30);
line.remove("$ELEMENT TYPE =");
lineList = line.split(" ",QString::SkipEmptyParts);
// creazione stringa del tipo di elemento
currentELtyp = lineList.at(1);
currentELtyp.chop(2);
currentELtyp.prepend("C");
if((lineList.at(1).contains("QUAD4LC")) || (lineList.at(1).contains("TRIA3LC")))
{
status.replace(1,"ELon");
}
lineList.clear();
} else if(status.at(0)=="LCon" && status.at(1)=="ELon")
{
line.chop(8); // elimina gli ultimi 8 caratteri evitando possibili errori quando il numero delle righe del pch si attacca all'ultimo valore
loadcase << currentLC;
eltyp<<currentELtyp;
lineList = line.split(" ",QString::SkipEmptyParts); //,QString::SkipEmptyParts
elid << lineList.at(0);
plyid << lineList.at(1);
sigmax << lineList.at(2);
sigmay << lineList.at(3);
lineList.clear();
line = in.readLine();countRow++;
line.chop(8); // elimina gli ultimi 8 caratteri evitando possibili errori quando il numero delle righe del pch si attacca all'ultimo valore
lineList = line.split(" ",QString::SkipEmptyParts);
sigmaxy << lineList.at(1);
sigmaxz << lineList.at(2);
sigmayz << lineList.at(3);
lineList.clear();
//
line = in.readLine();countRow++;
line = in.readLine();countRow++;
// solo per laminati!!
sigmaz << "0.0";
}
}
这是一个文本文件的示例:像这种格式的部分继续
650001 1 -1.919393E+05 5.581818E+05 8
-CONT- -1.747859E+03 -8.388188E+01 -4.930236E+01 9
-CONT- -8.986650E+01 5.581859E+05 -1.919434E+05 10
-CONT- 3.750646E+05 11