我怎么能继承QWidget和QThread? [英] how can i inherit from both QWidget and QThread?

查看:1396
本文介绍了我怎么能继承QWidget和QThread?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的类

I have a class like this

class GUI : public QWidget, public QThread

当我这样做时,我得到关于连接信号的错误。 错误说对连接的引用不明确。是否有继承这两种方法的方法?

When I do the above i get errors about connect signals. The error says Reference to "connect" is ambiguous. Is there a way to inherit from both?

谢谢

推荐答案

你不能。 QWidget QThread 继承(非虚拟)从 QObject 。因此,您不具有虚拟推导,因此有两个副本 QObject ,这会混淆编译器。 QObject 是这样专门设计的。请参阅:

You can't. Both QWidget and QThread inherit (non-virtually) from QObject. You therefore do not have virtual derivation, thus two copies of QObject, which confuses the compiler. QObject was specifically designed this way. See:

  • http://lists.trolltech.com/qt-interest/2006-10/msg00711.html
  • http://www.qtforum.org/article/23295/problem-opening-the-qfiledialog.html

有一些人据说绕过这个(现在找不到链接,但它在谷歌,我有两个星期有同样的麻烦前面),但它是不安全的。

There are some who allegedly went around this (can't find the link right now, but it's out there on Google, I had the same trouble two weeks ago), but it is unsafe at best.

编辑:最好的方法可能是让另一个对象从QThread继承,并将该对象作为 GUI class。这是大多数人在这件事上的解决方法。

the best way would probably be to have another object inherit from QThread and keep that object as a member in your GUI class. That is the sort of workaround most people do in this matter.

这篇关于我怎么能继承QWidget和QThread?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆