当前位置:   article > 正文

QT运行出错:QObject::connect: Parentheses expected以及QObject::connect: No such slot ***

qobject::connect: parentheses expected, signal qcombobox::currentindexchange

我在QGraphicsScene子类中添加了item的弹出菜单,并连接Action到槽函数,结果槽函数不起作用,输出:QObject::connect: No such slot ***

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
//选中item后弹出右键菜单
if  (event->button() == Qt::RightButton)
{
    m_pItemSelected = nullptr;
    foreach (QGraphicsItem *item, items(event->scenePos()))
    {
        
if  (item->type() == QGraphicsPixmapItem::Type)
        {
            m_pItemSelected = item;
            QMenu menu;
            QAction *removeAction = menu.addAction(
"Remove" );
            QAction *toTopLayerAction = menu.addAction(
"To Top Layer" );
            QAction *toBottomLayerAction = menu.addAction(
"To Bottom Layer" );
            QAction *toUpperLayerAction = menu.addAction(
"To Upper Layer" );
            QAction *toLowerLayerAction = menu.addAction(
"To Lower Layer" );
            connect(removeAction, SIGNAL(triggered()), 
this , SLOT(slotRemoveItem()));
            connect(toTopLayerAction, SIGNAL(triggered()), 
this , SLOT(slotLayerTop()));
            connect(toBottomLayerAction, SIGNAL(triggered()), 
this , SLOT(slotLayerBottom()));
            connect(toUpperLayerAction, SIGNAL(triggered()), 
this , SLOT(slotLayerUpper()));
            connect(toLowerLayerAction, SIGNAL(triggered()), 
this , SLOT(slotLayerLower()));
            menu.exec(event->screenPos());
            
break ;
        }
    }
}

 

在类中使用信号/槽时一定要加Q_OBJECT宏,signal和slots的参数要一样

槽函数加(): connect(toTopLayerAction, SIGNAL(triggered()), this, SLOT(slotLayerTop()));   // 正确

切记忘了():connect(toTopLayerAction, SIGNAL(triggered()), this, SLOT(slotLayerTop));      // 错误

转载于:https://www.cnblogs.com/MakeView660/p/10369462.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/297355
推荐阅读
相关标签
  

闽ICP备14008679号