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
Qt Code:
  1. #include <qapplication.h>
  2. #include <qdialog.h>
  3. #include <qpushbutton.h>
  4. #include <iostream>
  5.  
  6. class MyDialog : public QDialog
  7. {
  8. Q_OBJECT
  9. public:
  10. MyDialog(QWidget *parent = 0)
  11. : QDialog( parent, 0, FALSE, WDestructiveClose )
  12. {
  13. okBtn = new QPushButton( "&Ok", this );
  14. connect( okBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
  15. }
  16.  
  17. protected slots:
  18. void onOk()
  19. {
  20. std::cout << "onOk" << std::endl;
  21. sleep(1);
  22. accept();
  23. }
  24.  
  25. private:
  26. QPushButton* okBtn;
  27. };
  28.  
  29. int main(int argc, char **argv)
  30. {
  31. QApplication a(argc, argv);
  32.  
  33. QDialog mainWin(0);
  34. a.setMainWidget(&mainWin);
  35.  
  36. MyDialog *t = new MyDialog(0);
  37. t->show();
  38.  
  39. return a.exec();
  40.  
  41. }
  42.  
  43. #include "qtDialogExample.moc"
To copy to clipboard, switch view to plain text mode 

Thanks,
Curt