PDA

View Full Version : Slow processing and QProgressDialog not working as expected



poporacer
2nd November 2011, 05:20
I have a class function that gets a couple of queries to perform some data manipulation. One of the queries is used to iterate through the results and make the needed changes. The process takes approximately 7 seconds. I then put in a QProgressDialog to let the user know that something was happening. The QProcessDialog didn't show up for several seconds, and then when it did, it showed up and then completed in a fraction of a second. I moved the QProcessDialog up in the code as far as possible and it still took almost 3 seconds before it showed up. Is my computer just slow or are there issues in my code? I haven't had a chance to check it on another computer. The database is not that big (approximately 1000 rows) The rows iterated through is only around 200.
Here is the code:


void DlgEditPas::on_btnDelete_released()
{
if (ui->comboBox->currentIndex()== -1)
{
QMessageBox::warning(this, "Nothing Selected", "You do not have a PAS "
"Number selected",
QMessageBox::Ok);
return;
}
int test=QMessageBox::warning(this,"Delete PAS Number", "Are you sure you want to delete this PAS number? ",
QMessageBox::Yes | QMessageBox::No );
if (test==QMessageBox::No)
return;

// new location.... it takes almost 3 seconds to show up
QSqlQuery countQuery;
countQuery.exec("SELECT count(*) FROM position WHERE postType = 2");
countQuery.last();
int rowCount = countQuery.value(0).toInt();

QProgressDialog progress (this);
progress.setLabelText("Deleting relief coverage \n Searching Relief Positions");
progress.setRange(0,rowCount);
progress.setValue(0);
progress.setModal(true);
progress.setCancelButton(0);

//reset form data in case changes were made
m_formIsDirty=false;
on_comboBox_currentIndexChanged(ui->comboBox->currentIndex());

//prepare to delete
QString idNum=ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
QString postNum = ui->txtPostNum->text();
QSqlQuery deletePas;
deletePas.setForwardOnly(true);
deletePas.prepare("DELETE FROM pas WHERE id = " + idNum);
deletePas.exec();

QSqlQuery deletePosition;
deletePosition.setForwardOnly(true);
deletePosition.prepare("DELETE FROM position WHERE postNum = " + postNum);
deletePosition.exec();

//Delete relief info from relief posts

QSqlQuery reliefQuery;
reliefQuery.setForwardOnly(true);
QSqlQuery updateQuery;
updateQuery.setForwardOnly(true);
QString updateString;
reliefQuery.prepare ("SELECT id, mon, tue, wed, thu, fri, sat, sun FROM position "
"WHERE postType = 2"); // less than 200 rows
reliefQuery.exec();

//old QProgressDialog location here


int tempCount=0;


while(reliefQuery.next())
{
tempCount ++;
progress.setValue(tempCount);
for (int i=1; i<8; i++)
{
if (reliefQuery.value(i).toString()==postNum)
{
switch (i)
{
case 1: //day is Monday
updateString ="UPDATE position SET mon = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;

case 2: //day is Tuesday
updateString ="UPDATE position SET tue = '#####' WHERE id= " + reliefQuery.value(0).toString();
break;

case 3: //day is Wednesday
updateString ="UPDATE position SET wed = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;

case 4: //day is Thursday
updateString ="UPDATE position SET thu = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;

case 5: //day is Friday
updateString ="UPDATE position SET fri = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;

case 6: //day is Saturday
updateString ="UPDATE position SET sat = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;

case 7: //day is Sunday
updateString ="UPDATE position SET sun = '#####' WHERE id = " + reliefQuery.value(0).toString();
break;
}

updateQuery.prepare(updateString);
updateQuery.exec();
//qDebug() <<"update for delete relief query"<<updateQuery.lastError();


}
}
}
updateComboBox();
on_comboBox_currentIndexChanged(ui->comboBox->currentIndex());
}


Any ideas?

Santosh Reddy
2nd November 2011, 05:38
I guess you are having the QProgressDialogs's 4 second default delay, refer docs (http://doc.qt.nokia.com/4.7/qprogressdialog.html#details)

add progress.show(), this should show it earlier.

poporacer
2nd November 2011, 13:16
My understading of the docs is that the QProgressDialog will only show if the process takes longer than 4 seconds not that it takes 4 seconds to display. I tried the show() method and a blank dialog did show but then a couple seconds passed before the progress bar and text were displayed. Any other ideas?

Santosh Reddy
9th November 2011, 05:38
Try changing the order as below

QProgressDialog progress (this);
progress.setLabelText("Deleting relief coverage \n Searching Relief Positions");
progress.setRange(0,rowCount);
progress.setModal(true);
progress.setCancelButton(0);
progress.setValue(0);

gfrigon
21st January 2014, 15:39
>Any other ideas?

Try adding the following lines

progress.setMinimumDuration(0); // Change the Minimum Duration before displaying from 4 sec. to 0 sec.
progress.show(); // Make sure dialog is displayed immediately