我在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));      // 错误

QT运行出错:QObject::connect: Parentheses expected以及QObject::connect: No such slot ***的更多相关文章

  1. Qt经典出错信息之undefined reference to `vtable for classname

    原文链接:Qt经典出错信息之undefined reference to `vtable for classname 这个出错信息太常见了,用过Qt两个月以上的朋友基本上都能自己解决了,因为太经典了, ...

  2. MySQL运行出错:无法连接驱动、无root访问权限解决办法

    按照疯狂java讲义的13.3的程序,发现程序运行出错. 1.点开runConnMySql.cmd运行文件,出现如下结果: 2.用Editplus进行编译运行,如下结果: 报错定位到程序第18行,而第 ...

  3. 写shell,运行出错:syntax error near unexpected token `$’do\r”

    cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 写shell,运行出错:syntax error near unexpe ...

  4. Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互

    Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互 Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互

  5. vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏

    vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏 2014-03-27 11:34杜_柏 | 浏览 36144 次 请问这 ...

  6. 【转】MIUI8以及ViVO X9上在Android Studio运行出错集及其解决方案

    最近用一台红米4高配版(6.0)以及ViVo X9(7.1)来做测试机,它是小米MIUI系统的最新版本MIUI8,我的AS是2.3版本,在网上查看了相关问题,在小米5和红米note4x等配备了MIUI ...

  7. $ gulp watch 运行出错解决方法

    $ gulp watch 运行出错解决方法   $ gulp watch     如果你出现了如下报错信息: gulp-notify: [Laravel Elixir] Browserify Fail ...

  8. python文件打包发布(引用的包也可以加进来),打包出错解决了,运行出错解决了

    一开始,我以为,打包本来就很容易,可是没有..... 没想到打包还能遇到坑 T.T 打包步骤: 1.安装 pyinstaller (cmd) pip install pyinstaller 2.进入目 ...

  9. npm运行出错npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

    npm运行出错npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree 场景复现: 使用vue CLI创建项 ...

随机推荐

  1. 【Unity Shader】UnityCG.cginc中一些常用的函数

    // 摄像机方向(视角方向) float3 WorldSpaceViewDir(float4 v) // 根据模型空间中的顶点坐标 得到 (世界空间)从这个点到摄像机的观察方向 float3 Unit ...

  2. unix的sed 用法介绍

    sed是一个非交互性性文本编辑器,它编辑文件或标准输入导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文件.sed可以随意编辑小或大的文件,有许多sed命令用来编辑.删 ...

  3. ElasticSearch 深度分页解决方案 {"index":{"number_of_replicas":0}}

    常见深度分页方式 from+size es 默认采用的分页方式是 from+ size 的形式,在深度分页的情况下,这种使用方式效率是非常低的,比如 from = 5000, size=10, es ...

  4. 【javascript】js 获取 url 后的参数值

    以前写过一篇类似的博文(提取 url 的搜索字符串中的参数),但是个人觉得使用起来不是很方便,今天抽空重新写了个函数,该函数代码更加简洁. //获取 url 后的参数值 function getUrl ...

  5. linq操作符:串联操作符

    串联是一个将两个集合连接在一起的过程.在Linq中,这个过程通过Concat操作符实现.Concat操作符用于连接两个集合,生成一个新的集合.来看看Concat操作符的定义: public stati ...

  6. 使用 Gearman 实现分布式处理

    因为近来在研究 Mogilefs 的分布文件系统,在读读这个的源码,另外,为公司新设计了一个下载的系统,所以更加要深入研究一下,因为这个好东西是 Perl 写的,真不容易,在读这个的时间发现了几个好东 ...

  7. Linux gcc/g++链接编译顺序详解

    gcc/g++链接时对库的顺序要求 -Ldir Add directory dir to the list of directories to be searched for -l. -llibrar ...

  8. Process.StandardOutput

    Namespace:  System.DiagnosticsAssembly:  System (in System.dll) Syntax   C# C++ F# VB   [BrowsableAt ...

  9. TestNG 入门指导——理解testng.xml执行/不执行某个包,某个类,某个方法

    这一篇我们主要学习如下几个知识点: ⑴关于testng.xml ⑵创建一个测试套件 ⑶执行testng.xml ⑷在测试套件中创建多个测试用例 ⑸在用例中增加class,packages, metho ...

  10. mxnet卷积神经网络训练MNIST数据集测试

    mxnet框架下超全手写字体识别—从数据预处理到网络的训练—模型及日志的保存 import numpy as np import mxnet as mx import logging logging. ...