Results 1 to 4 of 4

Thread: qprogressbar without knowing the time

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qprogressbar without knowing the time

    In post QProgress Bar-Time Measuring 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.
    Qt Code:
    1. while (!in.atEnd()) {
    2. novo:
    3. line = in.readLine();
    4. next = in.pos();
    5. test.clear();
    6.  
    7. test = line.split(QRegExp("\\s+"));
    8. zero = test[2].toFloat(&ok);
    9. zero2 = test[3].toFloat(&ok2);
    10.  
    11. if(!ok || !ok2 || zero == 0.0 || zero2 == 0.0 || test.size() <= 3){
    12.  
    13. if(in.atEnd()){
    14. continue;
    15. }else {
    16. goto novo;
    17. }
    18. }else {
    19.  
    20. junto = test[2] + test[3];
    21.  
    22. while (!in.atEnd()) {
    23. line = in.readLine();
    24. comp.clear();
    25. comp = line.split(QRegExp("\\s+"));
    26. zero = comp[2].toFloat(&ok);
    27. zero2 = comp[3].toFloat(&ok2);
    28.  
    29. if (!ok || !ok2 || zero == 0.0 || zero2 == 0.0 || comp.size() <= 3){
    30. //relout << comp.size() << "Comp " << comp[3] << endl;
    31. if (varrer.atEnd())
    32. break;
    33. else
    34. continue;
    35. }else if (junto == comp[2]+comp[3]){
    36. relout << "Equal: Line " << comp[2] << " PT " << comp[3] << endl;
    37. file.close();
    38. break;
    39. //return;
    40. }
    41. }
    42. in.seek(next);
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jaca; 24th September 2009 at 03:06.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qprogressbar without knowing the time

    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

  3. #3
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qprogressbar without knowing the time

    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.
    Qt Code:
    1. int i = 0;
    2. while (!xx.atEnd()) {
    3. ++i;
    4. if ((i % 100) == 0) {
    5. QCoreApplication::processEvents();
    6. }
    7. // processes which need to be processed.
    8. }
    To copy to clipboard, switch view to plain text mode 

    any ideas?

  4. #4
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: qprogressbar without knowing the time

    Problem solved. I used QProgressDialog

Similar Threads

  1. How to constantly refresh time on a view
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2008, 13:44
  2. file time stamp preservation
    By baray98 in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2008, 01:13
  3. Replies: 1
    Last Post: 1st February 2008, 19:55
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 17:39
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 16:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.