I have an inherited QTreeWidget (called PackList) class and its parent is a KXmlGuiWindow. How can I access to the parent's slots?

我有一个继承的QTreeWidget(称为PackList)类,其父级是KXmlGuiWindow。如何访问父母的插槽?

I've tried getParent()->mySlot() from the QTreeWidget class but I've got

我已经尝试过来自QTreeWidget类的getParent() - > mySlot()但我已经有了

error: no matching function for call to 'PackList::mySlot()'

Does anybody know the correct way? Thanks

有人知道正确的方法吗?谢谢

2 个解决方案

#1


12

If you know the parent's class, you will have to cast parentWidget() to that class and then call your slot. Keep in mind whether or not it's a slot makes no difference in this case. You are just calling a method.

如果您知道父类,则必须将parentWidget()强制转换为该类,然后调用您的插槽。请记住,在这种情况下,它是否是一个插槽没有区别。你只是在调用一种方法。

((KXmlGuiWindow*)parentWidget())->mySlot();

You can make the call without casting by wiring up your signal to the slot.

您可以通过将信号连接到插槽来进行无需转换的呼叫。

connect( this, SIGNAL(mySignal()), parentWidget(), SLOT(mySlot()) );

Lastly, you can use QMetaObject::invokeMethod to call it if you don't want to cast it. That's probably overkill.

最后,如果您不想强制转换它,可以使用QMetaObject :: invokeMethod来调用它。这可能是矫枉过正的。

更多相关文章

  1. 在Linux上确定陈旧的Samba挂载的最快方法
  2. 关于主机远程唤醒(WOL,Wake on Lan)的几种方法
  3. Linux下安装mysql 出现依赖包冲突解决方法
  4. linux线程函数中代替sleep的方法
  5. 提高Linux安全性--hosts.allow, hosts.deny 文件修改方法
  6. windows下virtualbox中Ubuntu与主机通过ssh建立连接的方法
  7. Linux产生随机数的几种常见方法
  8. 视频去广告及商用软件Vip功能破解方法
  9. Ubuntu 安装XAMPP集成环境软件包 与 运行WordPress 的简单方法

随机推荐

  1. android插件化-apkplug中以监听方式获取O
  2. 关于 android.support.v7.widget.ListPop
  3. E/JavaBinder:FAILED BINDER TRANSACTION
  4. Android:无法在同一部手机上执行通过Linu
  5. [android基础]《疯狂android讲义》重点整
  6. 为什么使用KML数据检索Android版Google方
  7. Android开机启动过程分析
  8. 为什么Android API中有这么多花车?
  9. Android中Broadcast Receiver的两种注册
  10. android ontouch和onclick冲突处理