Results 1 to 8 of 8

Thread: Application only 'animates' once

  1. #1
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Application only 'animates' once

    I have a program that loads a file and does calculations. I show the progress and the final results using a qprogressbar and qlcdnumbers.

    When I run the program the first time, by loading an input file, the progress bar is set to visible and the LCD's are incremented one at a time. This works great the first time, but if I load another file all I see is the final results. My progress bar doesn't show and the LCD's don't increase one at a time, which is a great visual effect, when it works. The calculations are all correct the second time but there is no 'animation' except for the first time.

    I have tried resetting all the values back to zero on the LCD's to no avail, and haven't been able to find anything in the forums.

  2. #2
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application only 'animates' once

    maybe you should show us some of your codes, then we are able to find the mistake.
    good luck!

  3. #3
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application only 'animates' once

    Hope this helps! Feel free to ask any questions.
    Qt Code:
    1. /* This function opens the trace file and converts the addresses to a
    2.  * 32 bit binary representation. This function is called every time
    3.  * a file is opened */
    4. void MainWindow::on_actionOpen_triggered()
    5. {
    6. QString filename;
    7. filename = QFileDialog::getOpenFileName(this, tr("Select Trace File"),
    8. QDir::currentPath(),
    9. tr("Text Files (*.txt);;All Files (*)"));
    10.  
    11. if( filename.length() != 0 )
    12. {
    13. QString addr;
    14. bool ok;
    15. QStringList instruc;
    16.  
    17. /* Zero out the LCD's, display the filename, and show the progress bar */
    18. ui->writeLcd->display( 0 );
    19. ui->readLcd->display( 0 );
    20. ui->filenameText->setText( filename.mid( filename.lastIndexOf( "/") + 1 ) );
    21. ui->progressBar->setVisible(true);
    22.  
    23. /* Open File */
    24. QFile traceFile( filename );
    25. traceFile.open( QIODevice::ReadOnly );
    26. QTextStream inFileStream( &traceFile );
    27.  
    28. /* This loop reads in each request from the file a line at a time.
    29.   * Convert memory request to binary and store into array. Each entry in array
    30.   * contains a 32-bit address, and a leading R or W signifying a Read/Write */
    31. while( !inFileStream.atEnd() )
    32. {
    33. addr = inFileStream.readLine();
    34. /* First extract read/write */
    35. if( addr[0] == 'R' || addr[0] == 'r' )
    36. {
    37. /* Remove the R/W and any whitespace */
    38. addr.remove(0, 1);
    39. addr.trimmed();
    40. /* Convert to binary and store in array */
    41. addr = toBin( addr.toInt( &ok, 10 ) );
    42. instruc.append( 'R' + addr );
    43. ui->readLcd->display( ui->readLcd->value() + 1 );
    44. }
    45. else if( addr[0] == 'W' || addr[0] == 'w' )
    46. {
    47. /* Remove the R/W and any whitespace */
    48. addr.remove(0, 1);
    49. addr.trimmed();
    50. /* Convert to binary and store in array */
    51. addr = toBin( addr.toInt( &ok, 10 ) );
    52. instruc.append( 'W' + addr );
    53. ui->writeLcd->display( ui->writeLcd->value() + 1 );
    54. }
    55. }
    56. traceFile.close();
    57.  
    58. /* Set for progress bar */
    59. total = instruc.size() * 4;
    60. /* Create four cache objects with different size N */
    61. COACache a( 1, instruc );
    62. /* The SIGNALS and SLOTS are to update the GUI */
    63. connect( &a, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
    64. connect( &a, SIGNAL(updateMiss(int)), ui->n1MissLcd, SLOT(display(int)));
    65. connect( &a, SIGNAL( updateHit(int) ), ui->n1HitLcd, SLOT( display(int) ));
    66. connect( &a, SIGNAL(updateMRate(double)), ui->n1MRLcd, SLOT(display(double)));
    67. connect( &a, SIGNAL(updateHRate(double)), ui->n1HRLcd, SLOT(display(double)));
    68. connect( &a, SIGNAL(updateRep(int)), ui->n1RepLcd, SLOT(display(int)));
    69. a.simulate();
    70.  
    71. COACache b( 2, instruc );
    72. connect( &b, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
    73. connect( &b, SIGNAL(updateMiss(int)), ui->n2MissLcd, SLOT(display(int)));
    74. connect( &b, SIGNAL( updateHit(int) ), ui->n2HitLcd, SLOT( display(int) ));
    75. connect( &b, SIGNAL(updateMRate(double)), ui->n2MRLcd, SLOT(display(double)));
    76. connect( &b, SIGNAL(updateHRate(double)), ui->n2HRLcd, SLOT(display(double)));
    77. connect( &b, SIGNAL(updateRep(int)), ui->n2RepLcd, SLOT(display(int)));
    78. b.simulate();
    79.  
    80. COACache c( 4, instruc );
    81. connect( &c, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
    82. connect( &c, SIGNAL(updateMiss(int)), ui->n4MissLcd, SLOT(display(int)));
    83. connect( &c, SIGNAL( updateHit(int) ), ui->n4HitLcd, SLOT( display(int) ));
    84. connect( &c, SIGNAL(updateMRate(double)), ui->n4MRLcd, SLOT(display(double)));
    85. connect( &c, SIGNAL(updateHRate(double)), ui->n4HRLcd, SLOT(display(double)));
    86. connect( &c, SIGNAL(updateRep(int)), ui->n4RepLcd, SLOT(display(int)));
    87. c.simulate();
    88.  
    89. COACache d( 8, instruc );
    90. connect( &d, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
    91. connect( &d, SIGNAL(updateMiss(int)), ui->n8MissLcd, SLOT(display(int)));
    92. connect( &d, SIGNAL( updateHit(int) ), ui->n8HitLcd, SLOT( display(int) ));
    93. connect( &d, SIGNAL(updateMRate(double)), ui->n8MRLcd, SLOT(display(double)));
    94. connect( &d, SIGNAL(updateHRate(double)), ui->n8HRLcd, SLOT(display(double)));
    95. connect( &d, SIGNAL(updateRep(int)), ui->n8RepLcd, SLOT(display(int)));
    96. d.simulate();
    97.  
    98. ui->progressBar->setVisible(false);
    99. }
    100. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application only 'animates' once

    If you reuse the same QProgressBar object you must call QProgressBar::reset() before resuse it
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application only 'animates' once

    Thank you, I did try to reset it, but it didn't have any affect. Since I'm passing it a value of zero initially and then incrementing it up to 100, I shouldn't have to reset it right?

    I did notice that occasionally if I wait a while, maybe around 30 seconds, the application does work like it's supposed to, but not every time.

    I'm not sure if I'm describing this correctly, I've attached the program and two test cases.
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application only 'animates' once

    I don't think the binary will do us any good... Does "simulate" allow pending events to be processed?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application only 'animates' once

    No it doesn't.

    After finding out about pending events, I added QEventLoop::processEvents() into simulate. However this makes the calculations incredibly slow, so I set processEvents to be run once every one thousand calculations.

    Why would it work the first time, but not the second?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application only 'animates' once

    Quote Originally Posted by arkain View Post
    Why would it work the first time, but not the second?
    Hard to say. The best way is to debug and see but I'd assume you had some unitialized variable or something else that caused everything to look like it worked but in reality it didn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to detect a running application
    By yogesh in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2009, 10:22
  2. Qt Application + Web Integration -- Help needed
    By swamyonline in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2009, 11:59
  3. Start Qt application as Windows Service
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 10th May 2008, 17:23
  4. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37

Tags for this Thread

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.