#include #include #include #include #include #include #include #include #include #include int main(int argc, char** argv) { QApplication app(argc, argv); QMainWindow w; auto* f = new QFrame(); f->setFrameRect(QRect(0, 0, 700, 300)); auto* vlayout = new QVBoxLayout(); auto* hlayout = new QHBoxLayout(); auto* intro = new QTextEdit(); intro->setMinimumHeight(400); auto* text = new QTextEdit(); intro->insertHtml("

Test program to trigger the problem

" "

Pressing 1 will disable button 2 and vice versa; Reset will enable both buttons.

" "

Usign the keyboard shortcuts alt-1 quickly followed by alt-2 will trigger the bug. " "The \"2\" callback will be called even if the QPushButton 2 has been disabled.

" "

A workaround is to check btn.isEnabled() at the start of the callback

"); f->setLayout(vlayout); vlayout->addWidget(intro, 500); vlayout->addLayout(hlayout); vlayout->addWidget(text); auto* b1 = new QPushButton("&1"); auto* b2 = new QPushButton("&2"); auto* b3 = new QPushButton("&Reset"); QObject::connect(b1, &QPushButton::clicked, [b1, b2, text] { if (b1->isEnabled()) { text->insertHtml("B1 pushed;
"); } else { text->insertHtml("B1 pushed while disabled!;
"); } b2->setEnabled(false); }); QObject::connect(b2, &QPushButton::clicked, [b1, b2, text] { if (b2->isEnabled()) { text->insertHtml("B2 pushed;
"); } else { text->insertHtml("B2 pushed while disabled!;
"); } b1->setEnabled(false); }); QObject::connect(b3, &QPushButton::clicked, [b1, b2, text] { text->insertHtml("Reset pushed;
"); b1->setEnabled(true); b2->setEnabled(true); }); hlayout->addWidget(b1); hlayout->addWidget(b2); hlayout->addWidget(b3); w.setCentralWidget(f); w.show(); return app.exec(); } //! Windows entry point that calls into ANSI C++ main function. int CALLBACK WinMain(__in HINSTANCE, __in_opt HINSTANCE, __in LPSTR, __in int) { return main(__argc, __argv); }