5

I'm very new to Qt, and I need to simulate a click using the QTest Namespace and QTest::mouseClick. My problem is I would like to click a QMenu entry, defined as a QAction, but the mouseClick function doesn't allow me to pass this as an argument (only QWidgets or QWindows).

What could I do here?

demonplus
  • 5,613
  • 12
  • 49
  • 68
Fran M.
  • 79
  • 5

2 Answers2

4

You may use another way such direct triggers of your QAction's as far as you have them:

qAction->trigger();

This should have the same impact as mouse clicks in testing purposes.

demonplus
  • 5,613
  • 12
  • 49
  • 68
  • It does not completely have the same impact. You will need to manually close the menu afterwards, as the click is handled in QMenu itself. – loger9 Sep 19 '19 at 08:51
0

A QAction doesn't have any UI itself, so it can't be clicked.

It can, however, be plugged into several UI components, e.g. in a QMenu or a QToolBar, which can be clicked.

So if your tests needs to simulate some user interaction, you simulate it with the UI portion created for the action, e.g. the respective tool button on the toolbar, or entry in a menu

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22