Hello,

I have a GUI with lots of buttons. Each button should show a menu when clicked. I want to test this behaviour in the following unit test:


Qt Code:
  1. BOOST_AUTO_TEST_CASE(EachButtonHasMenuOnClick)
  2. {
  3. BOOST_FOREACH(QPushButton* elButton, m_perilib.findChildren<QPushButton*>())
  4. {
  5. // click on button
  6. QTest::mouseClick( elButton, Qt::LeftButton );
  7.  
  8. // check if menu is visible
  9. QMenu* elButtonMenu = elButton->menu();
  10. BOOST_REQUIRE(elButtonMenu);
  11. BOOST_CHECK_EQUAL(true, elButtonMenu->isVisible());
  12.  
  13. // click again (somewhere outside the menu) to close menu
  14. QTest::mouseClick( elButton, Qt::LeftButton );
  15. BOOST_CHECK_EQUAL(false, elButtonMenu->isVisible());
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 


But the problem is: the menu is opened modal, so QTest::mouseClick does not return until the user closes the menu by clicking anywhere. That is quite bad for an automated unit test... Is there any simple solution? Or do I have to use a different thread?

thx!
Felix