If you have a button on a dialog that you connect to the clicked signal which has a slot that calls accept() to close the window, if you double click the button fast enough you can end up with 2 calls to accept. I know I can work around this by disabling the button in the slot and re-enabling on show, but it seems like that shouldn't be neccessary. When would you want a button click to be triggered on a window that has already been hidden?
here's a quick example. If you double click the button, you get okOn printed twice
#include <qapplication.h>
#include <qdialog.h>
#include <qpushbutton.h>
#include <iostream>
{
Q_OBJECT
public:
: QDialog( parent,
0,
FALSE, WDestructiveClose
) {
connect( okBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
}
protected slots:
void onOk()
{
std::cout << "onOk" << std::endl;
sleep(1);
accept();
}
private:
};
int main(int argc, char **argv)
{
a.setMainWidget(&mainWin);
MyDialog *t = new MyDialog(0);
t->show();
return a.exec();
}
#include "qtDialogExample.moc"
#include <qapplication.h>
#include <qdialog.h>
#include <qpushbutton.h>
#include <iostream>
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget *parent = 0)
: QDialog( parent, 0, FALSE, WDestructiveClose )
{
okBtn = new QPushButton( "&Ok", this );
connect( okBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
}
protected slots:
void onOk()
{
std::cout << "onOk" << std::endl;
sleep(1);
accept();
}
private:
QPushButton* okBtn;
};
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QDialog mainWin(0);
a.setMainWidget(&mainWin);
MyDialog *t = new MyDialog(0);
t->show();
return a.exec();
}
#include "qtDialogExample.moc"
To copy to clipboard, switch view to plain text mode
Thanks,
Curt
Bookmarks