How to create virtual SLOT for action
Is it possible to send fonction for SLOT?
- //get actions
- a->setObjectName("act_"+t);
- widget->addAction(a);
- connect(a, SIGNAL(triggered()), ???, SLOT(slot));
- }
- }
- void Project::do_something_1(){...}
- void Project::do_something_2(){...}
- ...
- get_actions(ui->menu_actions_1, QStrinList()<<"name_1"<<"name_2", do_something_1());
- ...
- get_actions(ui->menu_actions_2, QStrinList()<<"name_3"<<"name_4", do_something_2());
Thanks
3 replies
What exactly are you trying to do ? Slot can be treated as any other c++ functions. Looks like you might want to look at QSignalMapper
As we look into the qobject.h file for the “connect” declaration, it becomes clear what to do.
I’ve simplified the declaration since it was big. But here we see that both SIGNAL and SLOT are const char pointer. Hence your code of choice is:
- //get actions
- a->setObjectName("act_"+t);
- widget->addAction(a);
- connect(a, SIGNAL(triggered()), slot);
- }
- }
- void Project::do_something_1(){...}
- void Project::do_something_2(){...}
- ...
- get_actions( ui->menu_actions_1, QStrinList()<<"name_1"<<"name_2", SLOT(do_something_1()) );
- ...
- get_actions( ui->menu_actions_2, QStrinList()<<"name_3"<<"name_4", SLOT(do_something_2()) );
You must log in to post a reply. Not a member yet? Register here!

