PDA

View Full Version : Application only 'animates' once



arkain
27th April 2009, 02:08
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.

sophister
27th April 2009, 08:31
maybe you should show us some of your codes, then we are able to find the mistake.
good luck!

arkain
28th April 2009, 02:04
Hope this helps! Feel free to ask any questions.


/* This function opens the trace file and converts the addresses to a
* 32 bit binary representation. This function is called every time
* a file is opened */
void MainWindow::on_actionOpen_triggered()
{
QString filename;
filename = QFileDialog::getOpenFileName(this, tr("Select Trace File"),
QDir::currentPath(),
tr("Text Files (*.txt);;All Files (*)"));

if( filename.length() != 0 )
{
QString addr;
bool ok;
QStringList instruc;

/* Zero out the LCD's, display the filename, and show the progress bar */
ui->writeLcd->display( 0 );
ui->readLcd->display( 0 );
ui->filenameText->setText( filename.mid( filename.lastIndexOf( "/") + 1 ) );
ui->progressBar->setVisible(true);

/* Open File */
QFile traceFile( filename );
traceFile.open( QIODevice::ReadOnly );
QTextStream inFileStream( &traceFile );

/* This loop reads in each request from the file a line at a time.
* Convert memory request to binary and store into array. Each entry in array
* contains a 32-bit address, and a leading R or W signifying a Read/Write */
while( !inFileStream.atEnd() )
{
addr = inFileStream.readLine();
/* First extract read/write */
if( addr[0] == 'R' || addr[0] == 'r' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'R' + addr );
ui->readLcd->display( ui->readLcd->value() + 1 );
}
else if( addr[0] == 'W' || addr[0] == 'w' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'W' + addr );
ui->writeLcd->display( ui->writeLcd->value() + 1 );
}
}
traceFile.close();

/* Set for progress bar */
total = instruc.size() * 4;
/* Create four cache objects with different size N */
COACache a( 1, instruc );
/* The SIGNALS and SLOTS are to update the GUI */
connect( &a, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &a, SIGNAL(updateMiss(int)), ui->n1MissLcd, SLOT(display(int)));
connect( &a, SIGNAL( updateHit(int) ), ui->n1HitLcd, SLOT( display(int) ));
connect( &a, SIGNAL(updateMRate(double)), ui->n1MRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateHRate(double)), ui->n1HRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateRep(int)), ui->n1RepLcd, SLOT(display(int)));
a.simulate();

COACache b( 2, instruc );
connect( &b, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &b, SIGNAL(updateMiss(int)), ui->n2MissLcd, SLOT(display(int)));
connect( &b, SIGNAL( updateHit(int) ), ui->n2HitLcd, SLOT( display(int) ));
connect( &b, SIGNAL(updateMRate(double)), ui->n2MRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateHRate(double)), ui->n2HRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateRep(int)), ui->n2RepLcd, SLOT(display(int)));
b.simulate();

COACache c( 4, instruc );
connect( &c, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &c, SIGNAL(updateMiss(int)), ui->n4MissLcd, SLOT(display(int)));
connect( &c, SIGNAL( updateHit(int) ), ui->n4HitLcd, SLOT( display(int) ));
connect( &c, SIGNAL(updateMRate(double)), ui->n4MRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateHRate(double)), ui->n4HRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateRep(int)), ui->n4RepLcd, SLOT(display(int)));
c.simulate();

COACache d( 8, instruc );
connect( &d, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &d, SIGNAL(updateMiss(int)), ui->n8MissLcd, SLOT(display(int)));
connect( &d, SIGNAL( updateHit(int) ), ui->n8HitLcd, SLOT( display(int) ));
connect( &d, SIGNAL(updateMRate(double)), ui->n8MRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateHRate(double)), ui->n8HRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateRep(int)), ui->n8RepLcd, SLOT(display(int)));
d.simulate();

ui->progressBar->setVisible(false);
}
}

mcosta
28th April 2009, 10:54
If you reuse the same QProgressBar object you must call QProgressBar::reset() before resuse it

arkain
28th April 2009, 23:22
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.

wysota
28th April 2009, 23:33
I don't think the binary will do us any good... Does "simulate" allow pending events to be processed?

arkain
29th April 2009, 02:20
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?

wysota
29th April 2009, 09:09
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.