Momergil
30th January 2013, 12:43
Hello!
I add a QProgressDialog in my project that shows a charge-and-calculate progress. After the process is complete, the QProgressDialog is supposed to be closed and deleted. But there is the possibility that the user might want to cancel the process, so I connected a slot to QProgressDialog's cancel() signal, so whenever the cancel() signal is emmited while clicking in QProgressDialog's Cancel button, the QProgressDialog is closed and deleted, and when its not, it is closed and deleted normally after the charge-and-calculate process is complete.
Doing so, I found that the cancel() signal is beeing emitted by QProgressDialog even when the Cancel button is NOT triggered, that is, when the user allows the progress normally to its end. SO what happens is that my software crashes, since it tries to do a close() and delete in the normal code while the erroneos cancel slot had already done that before due to this erroneos cancel emited signal.
Could this be a bug in Qt?
Personally I see no problem in my code, it's quite simple:
progressBarCarregaAtivos = new QProgressDialog(this);
progressBarCarregaAtivos->setWindowTitle("Loading...");
progressBarCarregaAtivos->setMinimum(0);
progressBarCarregaAtivos->setMaximum(filesNames.size());
progressBarCarregaAtivos->setLabelText("Loading shares data...");
progressBarCarregaAtivos->setWindowModality(Qt::ApplicationModal);
connect(progressBarCarregaAtivos,SIGNAL(canceled() ),this,SLOT(slotProgressBarCanceled()));
progressBarCarregaAtivos->show();
void MainWindow::slotProgressBarCanceled() //being called even when Cancel is not triggered
{
/*!
\brief chamado caso se aperte em "cancelar" quando esta sendo feito
o download em modo local. */
qDebug() << "Cancelou carregamento de ativos";
timerCarregaVarios->stop();
progressBarCarregaAtivos->close();
SAFEDELETE(timerCarregaVarios);
SAFEDELETE(progressBarCarregaAtivos);
counter_carregaVarios = 0;
carregaAtivosMux = 0;
filesNames.clear();
vetor_ativos.clear();
Flags.start_automation = false;
ui->actionStop_automation->setDisabled(false);
ui->actionAnalyse_a_share->setDisabled(false);
ui->actionReviewWindow->setDisabled(false);
ui->actionAlarms->setDisabled(false);
slotMemoLog("Carregamento local cancelado.","","\n");
}
//Normal end code
timerCarregaVarios->stop();
SAFEDELETE(timerCarregaVarios); //???
disconnect(progressBarCarregaAtivos,SIGNAL(cancele d()));
progressBarCarregaAtivos->close();
SAFEDELETE(progressBarCarregaAtivos)
I add a QProgressDialog in my project that shows a charge-and-calculate progress. After the process is complete, the QProgressDialog is supposed to be closed and deleted. But there is the possibility that the user might want to cancel the process, so I connected a slot to QProgressDialog's cancel() signal, so whenever the cancel() signal is emmited while clicking in QProgressDialog's Cancel button, the QProgressDialog is closed and deleted, and when its not, it is closed and deleted normally after the charge-and-calculate process is complete.
Doing so, I found that the cancel() signal is beeing emitted by QProgressDialog even when the Cancel button is NOT triggered, that is, when the user allows the progress normally to its end. SO what happens is that my software crashes, since it tries to do a close() and delete in the normal code while the erroneos cancel slot had already done that before due to this erroneos cancel emited signal.
Could this be a bug in Qt?
Personally I see no problem in my code, it's quite simple:
progressBarCarregaAtivos = new QProgressDialog(this);
progressBarCarregaAtivos->setWindowTitle("Loading...");
progressBarCarregaAtivos->setMinimum(0);
progressBarCarregaAtivos->setMaximum(filesNames.size());
progressBarCarregaAtivos->setLabelText("Loading shares data...");
progressBarCarregaAtivos->setWindowModality(Qt::ApplicationModal);
connect(progressBarCarregaAtivos,SIGNAL(canceled() ),this,SLOT(slotProgressBarCanceled()));
progressBarCarregaAtivos->show();
void MainWindow::slotProgressBarCanceled() //being called even when Cancel is not triggered
{
/*!
\brief chamado caso se aperte em "cancelar" quando esta sendo feito
o download em modo local. */
qDebug() << "Cancelou carregamento de ativos";
timerCarregaVarios->stop();
progressBarCarregaAtivos->close();
SAFEDELETE(timerCarregaVarios);
SAFEDELETE(progressBarCarregaAtivos);
counter_carregaVarios = 0;
carregaAtivosMux = 0;
filesNames.clear();
vetor_ativos.clear();
Flags.start_automation = false;
ui->actionStop_automation->setDisabled(false);
ui->actionAnalyse_a_share->setDisabled(false);
ui->actionReviewWindow->setDisabled(false);
ui->actionAlarms->setDisabled(false);
slotMemoLog("Carregamento local cancelado.","","\n");
}
//Normal end code
timerCarregaVarios->stop();
SAFEDELETE(timerCarregaVarios); //???
disconnect(progressBarCarregaAtivos,SIGNAL(cancele d()));
progressBarCarregaAtivos->close();
SAFEDELETE(progressBarCarregaAtivos)