single QProgressDialog button push produces two signals
-
@mzimmers said in single QProgressDialog button push produces two signals:
m_fileTransferDialog
You only delete the QProgressDialog when it's canceled, at least in the show you've shown us.
@Christian-Ehrlicher good point, and I'll correct that. I don't think it has any bearing on this problem though, as this issue occurs the first time through the code.
-
@Christian-Ehrlicher good point, and I'll correct that. I don't think it has any bearing on this problem though, as this issue occurs the first time through the code.
@mzimmers
If you sayrelayTransferCanceled()is called twice, what is the value ofm_fileTransferDialogsecond time? You can put a breakpoint to see it hittingdelete m_fileTransferDialog;. So really it should crash on the second time (on them_fileTransferDialog->close();), unless the calls have quite distinctm_fileTransferDialog;s? -
@mzimmers
If you sayrelayTransferCanceled()is called twice, what is the value ofm_fileTransferDialogsecond time? You can put a breakpoint to see it hittingdelete m_fileTransferDialog;. So really it should crash on the second time (on them_fileTransferDialog->close();), unless the calls have quite distinctm_fileTransferDialog;s?@JonB that's exactly what it does -- crash on the second close() attempt.
In looking at the canceled() signal, I wonder if I should disconnect it from the default slot cancel() before I use it. I notice that closing the window also triggers the signal.
EDIT:
Tried the above, no help. I'm definitely doing something to cause this code to execute twice, but I sure don't know what it is. Here's the latest effort:
void Widget::showFileTransfer() { m_fileTransferDialog = new QProgressDialog("Transferring file", "Abort Transfer", 0, 100, this); QObject::connect(this, &Widget::progressChanged, m_fileTransferDialog, &QProgressDialog::setValue); QObject::connect(m_fileTransferDialog, &QProgressDialog::canceled, this, &Widget::relayTransferCanceled); m_fileTransferDialog->show(); } void Widget::relayTransferCanceled() { emit transferCanceled(); deleteProgressDialog(false);void Widget::deleteProgressDialog(bool success) } void Widget::deleteProgressDialog(bool success) { QString title; QString text; if (success) { title = "File Transfer Complete"; text = "The file transfer has completed."; } else { title = "File Transfer Did Not Complete"; text = "The file transfer did not complete successfully."; } QMessageBox *qmb; qmb = new QMessageBox(QMessageBox::NoIcon, title, text, QMessageBox::Ok, this); qmb->exec(); m_fileTransferDialog->close(); delete m_fileTransferDialog; delete qmb; } -
How many file transfert can you have ?
If several, you should reconsider your dialog and give it the capability to show information for more than one transfert.
-
@JonB that's exactly what it does -- crash on the second close() attempt.
In looking at the canceled() signal, I wonder if I should disconnect it from the default slot cancel() before I use it. I notice that closing the window also triggers the signal.
EDIT:
Tried the above, no help. I'm definitely doing something to cause this code to execute twice, but I sure don't know what it is. Here's the latest effort:
void Widget::showFileTransfer() { m_fileTransferDialog = new QProgressDialog("Transferring file", "Abort Transfer", 0, 100, this); QObject::connect(this, &Widget::progressChanged, m_fileTransferDialog, &QProgressDialog::setValue); QObject::connect(m_fileTransferDialog, &QProgressDialog::canceled, this, &Widget::relayTransferCanceled); m_fileTransferDialog->show(); } void Widget::relayTransferCanceled() { emit transferCanceled(); deleteProgressDialog(false);void Widget::deleteProgressDialog(bool success) } void Widget::deleteProgressDialog(bool success) { QString title; QString text; if (success) { title = "File Transfer Complete"; text = "The file transfer has completed."; } else { title = "File Transfer Did Not Complete"; text = "The file transfer did not complete successfully."; } QMessageBox *qmb; qmb = new QMessageBox(QMessageBox::NoIcon, title, text, QMessageBox::Ok, this); qmb->exec(); m_fileTransferDialog->close(); delete m_fileTransferDialog; delete qmb; }@mzimmers said in single QProgressDialog button push produces two signals:
@JonB that's exactly what it does -- crash on the second close() attempt.
Aha! OK, you didn't say that :)
So I presume when you hit each time the stacktraces don't reveal anything different?
-
@mzimmers said in single QProgressDialog button push produces two signals:
@JonB that's exactly what it does -- crash on the second close() attempt.
Aha! OK, you didn't say that :)
So I presume when you hit each time the stacktraces don't reveal anything different?
-
Sorry about that. The stack quickly enters Qt space, so I can't do much with it myself. Interesting, though, that the 2nd iteration shows my code on level 17 whereas the 1st one doesn't.
@mzimmers
So the second call to the slot is coming from yourWidget::deleteProgressDialog()on linem_fileTransferDialog->close();I know nothing about this, but does closing the dialog cause the
QProgressDialog::canceledsignal to be raised? Does unconnecting that signal prior tom_fileTransferDialog->close();solve your problem? take a look at https://www.qtcentre.org/threads/53056-QProgressDialog-cancel-signal-is-emitted-always ?Also, you are calling
deleteProgressDialog()in yourrelayTransferCanceled()slot. Should you/is it safe to be goingm_fileTransferDialog->close(); delete m_fileTransferDialog;from a slot? Should it be more link
deleteLater()?These are just thoughts for you! I know nothing... :)
-
Hi Jon - all good suggestions, and all appreciated. I don't know of any reason I can't delete from a slot, but I did convert it to deleteLater().
I thought I'd already tried your suggestion to use disconnect() without success, but I tried it again, and now it seems to work.
void Widget::showFileTransfer() { m_fileTransferDialog = new QProgressDialog("Transferring file", "Abort Transfer", 0, 100, this); QObject::connect(this, &Widget::progressChanged, m_fileTransferDialog, &QProgressDialog::setValue); QObject::connect(m_fileTransferDialog, &QProgressDialog::canceled, this, &Widget::relayTransferCanceled); m_fileTransferDialog->show(); } void Widget::relayTransferCanceled() { QObject::disconnect(m_fileTransferDialog, &QProgressDialog::canceled, nullptr, nullptr); emit transferCanceled(); deleteProgressDialog(FILE_TRANSFER_CANCELED); }I'd like to get to the bottom of this issue, so I'm going to leave it as unsolved for a few days, but at least I have a workaround. Thanks.
-
I think I may have found at least part of the problem. It seems that my call to close() emits the canceled() signal, which was getting me in trouble, as my slot wasn't prepared for a signal under these circumstances. I guess I'm not supposed to call close(), which is actually a slot.
My app seems to be working now. I'm going to keep this unsolved for another day, just in case someone has something else to add.
So