lundi 23 novembre 2020

Qt/C++ How can I disconnect a QProgressDialog::canceled signal to its QProgressDialog::cancel slot?

I have a QProgressDialog and I would like to override its cancel() slot to change its behavior.

Instead of closing the dialog, I would like to do some other operations and then close the dialog after a QThread to finish before closing the dialog.

I tried to disconnect the canceled/cancel signal/slot couples and the reconnect with the new behavior but it does not seem to change much.

As as soon as I click on the cancel button, the progress dialog gets closed first and then my lambda get executed anyway.

Qobject::disconnect(m_progressdialog, &QProgressDialog::canceled, m_progressdialog, &QProgressDialog::cancel);

Qobject::connect(m_progressdialog, &QProgressDialog::canceled, [](){
  // continue displaying the dialog as an occupation bar
  m_progressdialog->setValue(0);
  // do some other things
  // a lot of code
  // ...
  // only later close the dialog
  m_progressdialog->close();
});

Is there a way to do this correctly?

Aucun commentaire:

Enregistrer un commentaire