PDA

View Full Version : QThread && QTextStream readline()



spawnsito
5th August 2011, 18:55
Hello everyone. I´m Spawnsito and I need help.

I am making an application where I need to read a file too heavy. The file has a default format:
XXXXX, YYYYYY, HEIGHT -> all are number.

I'm reading this file from a QThread through QTextStream. Everything works fine until the thread emit the progress that has processed the file. At iteration after emit, the function readline() in QTextStream take a partial string of the file.

If I remove the emit of the sign of progress, the thread is working properly, however the progress bar is not useful.

I hope I have explained my problem correctly.


void CargarDemThread::run(){
float altura;
QFile file(_rutaDem);
int progreso = 1;
if (file.open(QIODevice::Text | QIODevice::ReadOnly)){
qint64 size = file.size();
QTextStream in(&file);
while(!in.atEnd()){
f = in.readLine();
sl = f.split(",");
altura = sl.at(2).toFloat();
_dem->addValue(altura);
if (in.pos/size()*100>progreso){
emit progress(progreso);
progreso++;
}
}
}