python QThread.run 参数 - 版本之间发生变化?

发布于 2024-09-10 02:02:50 字数 296 浏览 1 评论 0原文

在我的代码(python2.6,PyQt4)中,我做了这样的事情:

def myRun():
    doStuff
thread = QtCore.QThread()
thread.run = myRun
thread.start()

在我的gentoo机器上,这工作得很好。在 ubunut(9.10,Karmic Koala)上它不起作用,它说: 类型错误:myRun() 不接受参数(给定 1)

QT 中是否发生了变化?我怎样才能使这在两台机器上都工作?

谢谢! 内森

In my code (python2.6, PyQt4) I do something like this:

def myRun():
    doStuff
thread = QtCore.QThread()
thread.run = myRun
thread.start()

On my gentoo machine, this works perfectly. On a ubunut (9.10, Karmic Koala) it does not work, it says:
Type Error: myRun() takes no arguments (1 given)

Did something change in QT? How can I make this work on both machines?

Thanks!
Nathan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哑剧 2024-09-17 02:02:50

我不确定那是如何运作的;你应该继承 QThread 并重写 run() 方法。 “不带参数”错误是因为 QT 运行时试图将“self”作为类方法的第一个参数传递。以下内容更接近您的需要:

def myThread(QtCore.QThread):
    def run(self):
        pass

thread = myThread()
thread.start()

更新:与原始内容更加匹配。

def myRun():
    doStuff

thread = QtCore.QThread()
thread.run = lambda self: myRun()
thread.start()

I'm not sure how that ever worked; you're supposed to subclass QThread and override the run() method. The "takes no arguments" error is because the QT runtime is trying to pass "self" as the first argument of a class method. The following is closer to what you need:

def myThread(QtCore.QThread):
    def run(self):
        pass

thread = myThread()
thread.start()

UPDATED: Matching the original a bit more.

def myRun():
    doStuff

thread = QtCore.QThread()
thread.run = lambda self: myRun()
thread.start()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文