Fran M.
Fran M.

Reputation: 79

How to use QTest::mouseClick with QAction

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?

Upvotes: 5

Views: 1538

Answers (2)

Kevin Krammer
Kevin Krammer

Reputation: 5207

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

Upvotes: 0

demonplus
demonplus

Reputation: 5811

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.

Upvotes: 4

Related Questions