How to trigger an action without using signal-slot connection?

c++, qt

Solution

You can connect signals to non-slot methods using the new `QObject::connect` syntax in Qt 5. It looks like this:

connect(action, &QAction::triggered, this, &MyClass::doSomeFunction);

In this example, `MyClass::doSomeFunction` does not need to be a slot. Here is a more in depth explanation.

If you actually want to trigger a QAction, you can just do so directly, without using signals or slots:

action->trigger();

Problem

The usual way to trigger a Qt action is to use signal-slot connection. Any other way to do it since my function is not a slot? Such as some direct calls?

Original source