Pergunta

I am doing something like this:

MyClass::MyClass(QWidget *parent) : QLabel(parent)
{
    this->MyMenu = new QMenu();

    QAction* act_del = new QAction(MyMenu);
    act_delete->setText("MyAction");

    MyMenu->addAction(act_del);

    QObject::connect(act_del,SIGNAL(triggered()),this,SLOT(MySlot()));
}

void MyClass::MySlot()
{
    //Not called
}

Any suggestion on when the SIGNAL is triggered the SLOT is not called. Here is where the menu is displayed:

void MyClass::contextMenuEvent(QContextMenuEvent *ev)
{
    QPoint globalPos = this->mapToGlobal(ev->pos());

    QAction* selectedItem = MyMenu->exec(globalPos);
    if (selectedItem)
    {

    }
    else
    {
        // nothing was chosen
    }
}

Any suggestions on why the SLOT is not called?

Foi útil?

Solução

MyClass needs to contain the Q_OBJECT macro for the signal-slot connections to work.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top