开发者

python QThread.run parameters - changed between versions?

开发者 https://www.devze.com 2023-01-07 20:55 出处:网络
In my code (python2.6, PyQt4) I do something like this: def myRun(): doStuff thread = QtCore.QThread() thread.run 开发者_StackOverflow中文版= myRun

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

def myRun():
    doStuff
thread = QtCore.QThread()
thread.run 开发者_StackOverflow中文版= 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


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号