I have a problem with reading file, specific is I want to make a small dictionary. In file which I need to read has content like this:
a Ph P6
a snsr CA
a b c fb Dj
a b c - book i+ BS
A except B gate oOPa y
a font kQ BU
[....]
It has about 109.000 lines, and file just has size about 2MB. In my QT app, I coded like this to read and add items to QListWidget:
QString sWord;
QFile inFile("C:\EV\ev.index");
inFile.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream in(&inFile);
while(!in.atEnd())
{
sWord = in.readLine();
myListWidget->addItem(sWord); //myListWidget is a QListWidget
}
But it reads too long! At first I think reason is my app reads line by line, so I coded its again like this:
QString data;
QStringList listWord;
QFile inFile("C:\EV\ev.index");
inFile.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream in(&inFile);
data.append(in.readAll());
listWord.append(data.split('
'));
myListWidget->addItems(listWord);
inFile.close();
It works faster!(about 5 seconds since app launched), still long, I want it to read faster. What I have to do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…