c – Qt:发出信号时不调用信号处理程序
作者:互联网
我正在做这样的事情:
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
}
关于何时触发SIGNAL的任何建议都不会被调用.这是显示菜单的位置:
void MyClass::contextMenuEvent(QContextMenuEvent *ev)
{
QPoint globalPos = this->mapToGlobal(ev->pos());
QAction* selectedItem = MyMenu->exec(globalPos);
if (selectedItem)
{
}
else
{
// nothing was chosen
}
}
为什么没有调用SLOT的任何建议?
解决方法:
MyClass需要包含Q_OBJECT宏以使信号槽连接起作用.
标签:qtcore,c,qt,qt-signals 来源: https://codeday.me/bug/20190831/1774109.html