多继承自 QObject 和 QRunnable 错误 [英] multi inherit from QObject and QRunnable error

查看:31
本文介绍了多继承自 QObject 和 QRunnable 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pyqt4.我有一个从 QObject 和 QRunnable 继承的类,如下所示:

I'm using pyqt4. I have a class multi inherited from QObject and QRunnable like this:

class DownloadTask(QObject, QRunnable):
    def __init__(self):
        QObject.__init__(self)
        QRunnable.__init__(self)
        self.setAutoDelete(False)

DownloadTask 实例初始化时,最后一行抛出异常:

When an instance of DownloadTask is initializing, the last line throws exception:

TypeError: could not convert 'DownloadTask' to 'QRunnable'

但我认为在语法上是正确的,QRunnable 有 setAutoDelete 方法.为什么它不能转换为 QRunnable?

But I think it is correct in grammer, QRunnable has the method setAutoDelete. Why can't it convert to QRunnable?

更新:
我打算使用 QThreadPool 来管理多线程从 Internet 下载资源,并在完成后发出信号.我该怎么做?

Update:
I intend to use QThreadPool to manage multi threads downloading resources from Internet, and emit a signal after finished. How can I do that?

推荐答案

PyQt 参考指南 > 需要注意的事项 > 多重继承:

不可能定义一个新的 Python 类,该类从多个 Qt 类中分出子类.

It is not possible to define a new Python class that sub-classes from more than one Qt class.

这篇关于多继承自 QObject 和 QRunnable 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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