conectar una QAction a una ranura virtual?

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.

Aquí está el código:

class Command  : QObject

    Command(QWidget *parent);

public slots:
    virtual void execute();

    QAction *commandAct;

Command::Command(QWidget *parent)
    commandAct = new QAction(parent);

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.

preguntado el 30 de enero de 12 a las 19:01

1 Respuestas

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.

Respondido el 31 de enero de 12 a las 00:01

does it apply on Qt 4.8 as well? - WonderfulMe

@Mogi yes, this is the case for all Qt versions. The API and internal implementation for the connections might have changed over the years, but not the fact that a slot execution is just a method call of that slot method. - Frank Osterfeld

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.