pyqt6中的螺纹的直接替换。

发布于 2025-02-12 21:07:45 字数 578 浏览 1 评论 0原文

我当前正在使用螺纹。thread()来执行耗时的python命令,因此不应影响我的用户界面。通常,要执行的函数是类函数,并将其移至同一类的其他类函数中的线程,与

self.t = threading.Thread(target = self.long_function_to_run, args=(), kwargs={})
self.t.daemon = True
self.t.start()

现在类似的代码,我想将所有内容移动以使用QThread,以便能够使用信号和插槽而不是必须依靠queue() - 标题。

尽管如此,我必须创建自己的工人级,从qobjectqthread(如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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文