pyqt6中的螺纹的直接替换。
我当前正在使用螺纹。thread()
来执行耗时的python命令,因此不应影响我的用户界面。通常,要执行的函数是类函数,并将其移至同一类的其他类函数中的线程,与
self.t = threading.Thread(target = self.long_function_to_run, args=(), kwargs={})
self.t.daemon = True
self.t.start()
现在类似的代码,我想将所有内容移动以使用QThread,以便能够使用信号和插槽而不是必须依靠queue()
- 标题。
尽管如此,我必须创建自己的工人级,从qobject
或qthread
(如https://stackoverflow.com/a/a/6789205/2546099 ),然后执行此类。这会增加大量的开销,因此我想知道是否有与我最初的方法类似的其他选择,而没有子类别?
I am currently using threading.Thread()
to execute python-functions which are time-consuming, and therefore should not impact my user interface. Typically, the functions to be executed are class functions, and are moved into threads in other class functions of the same class with a code similar to
self.t = threading.Thread(target = self.long_function_to_run, args=(), kwargs={})
self.t.daemon = True
self.t.start()
Now, I would like to move everything to use QThread instead, to be able to use signals and slots instead of having to rely on Queue()
-queues.
Nevertheless, to do that, I have to create my own worker-class, subclass it from either QObject
or QThread
(as described in https://stackoverflow.com/a/6789205/2546099), and then execute this class. This would add significant overhead, and therefore I was wondering if there are any alternatives similar to my initial approach, without subclassing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论