PDA

View Full Version : qprogressbar without knowing the time



jaca
24th September 2009, 03:02
In post QProgress Bar-Time Measuring (http://www.qtcentre.org/forum/f-qt-programming-2/t-qprogress-bar-time-measuring-7006.html/?highlight=qprogress) is used a known time. How do I do if I do not know the time?
I have a program that read a file with many lines. This program takes the first line and test whether it is equal to some other line of the file. Take the next does the same thing to the end. But the program hangs and only responds when you finish the test.
I would like a QProgressBar controlling it. But I have no idea.
Someone help me? Thanks.


while (!in.atEnd()) {
novo:
line = in.readLine();
next = in.pos();
test.clear();

test = line.split(QRegExp("\\s+"));
zero = test[2].toFloat(&ok);
zero2 = test[3].toFloat(&ok2);

if(!ok || !ok2 || zero == 0.0 || zero2 == 0.0 || test.size() <= 3){

if(in.atEnd()){
continue;
}else {
goto novo;
}
}else {

junto = test[2] + test[3];

while (!in.atEnd()) {
line = in.readLine();
comp.clear();
comp = line.split(QRegExp("\\s+"));
zero = comp[2].toFloat(&ok);
zero2 = comp[3].toFloat(&ok2);

if (!ok || !ok2 || zero == 0.0 || zero2 == 0.0 || comp.size() <= 3){
//relout << comp.size() << "Comp " << comp[3] << endl;
if (varrer.atEnd())
break;
else
continue;
}else if (junto == comp[2]+comp[3]){
relout << "Equal: Line " << comp[2] << " PT " << comp[3] << endl;
file.close();
break;
//return;
}
}
in.seek(next);
}
}

aamer4yu
24th September 2009, 10:29
You could try increasing the bar inside the loop where you read the file contents.
When it reaches 100 reduce it by say 20, and continue.

Once out of the loop, set it to 100

jaca
25th September 2009, 02:55
But that does not solve the lock of the window. The file contains 4500 lines. During the process the program tests if any line is equal. This generates a lot of information and just locking the widget parent.
I tried to use, but did not worked.


int i = 0;
while (!xx.atEnd()) {
++i;
if ((i % 100) == 0) {
QCoreApplication::processEvents();
}
// processes which need to be processed.
}


any ideas?

jaca
25th September 2009, 23:45
Problem solved. I used QProgressDialog :p