user1899020 user1899020 - 1 year ago 121
C++ Question

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

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?

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download