Reputation: 13575
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?
Upvotes: 2
Views: 6633
Reputation: 1478
If connect in main(), it can be like this:
void windowAbout(){
QMessageBox aboutMB(QMessageBox::NoIcon, "About", "This is a weather forcast !");
aboutMB.setIconPixmap(QPixmap(":/icon.ico"));
aboutMB.exec();
}
int main(){
......
QObject::connect(aboutAction, &QAction::triggered, &app, &windowAbout);
......
}
Upvotes: 1
Reputation: 8788
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();
Upvotes: 14
Reputation: 22187
You can add slot which you will connect with the signal, and you can call your function within it.
Upvotes: 0