Reputation: 1211
I am trying to a create a command class hierarchy. Basically each command will be bound to a QAction. Once the action is triggered, it will call a virtual method.
Here is the code:
class Command : QObject
{
Q_OBJECT
public:
Command(QWidget *parent);
public slots:
virtual void execute();
protected:
QAction *commandAct;
};
Command::Command(QWidget *parent)
{
commandAct = new QAction(parent);
parent->addAction(commandAct);
connect(commandAct,SIGNAL(triggered()),this,SLOT(execute()));
}
QAction *Command::getAction()
{
return commandAct;
}
Now if I derive a class and override the execute method, will it be called like it is supposed to be?
I need this to work cross platform.
Upvotes: 1
Views: 3170
Reputation: 25165
Yes, overriding virtual slots works just with every other virtual method. In the end, the signal/slot connect is just a method call, which can be either virtual or non-virtual.
Upvotes: 2