gpt4 book ai didi

How use asyncio with pyqt6?(如何将Asyncio与pyqt6一起使用?)

转载 作者:bug小助手 更新时间:2023-10-24 19:55:35 25 4
gpt4 key购买 nike



qasync doesn't support pyqt6 yet and I'm trying to run discord.py in the same loop as pyqt but so far I'm not doing the best. I've tried multiprocess, multithread, and even running synchronous code from non-synchronous code but I either end up with blocking code that makes the pyqt program non responsive or it just outright doesn't work. Can somebody please point me in the right direction?

Qasync还不支持pyqt6,我正尝试在与pyqt相同的循环中运行discord.py,但到目前为止我还没有做到最好。我尝试过多进程、多线程,甚至从非同步代码运行同步代码,但我要么以阻塞代码而导致pyqt程序无响应,要么就是它根本无法工作。有谁能给我指个方向吗?


更多回答

Why don't you use PyQt5 or PySide2 or PySide6 until qasync supports PyQt6?

在qasync支持PyQt6之前,为什么不使用PyQt5、PySide2或PySide6呢?

before I realized I would need it I created my program with pyqt6, And porting it to pyqt5 has been a little rough. I'd need to recreate my program which wouldn't be ideal :/

在我意识到我将需要它之前,我使用pyqt6创建了我的程序,并且将其移植到pyqt5有点困难。我需要重新创建我的程序,这将不是理想的:/

@Lino right now PyQt6 has little differences from 5, and unless you're using specific new features added in Qt6 the only big difference is the usage of Enums. Also, AFAIK, if you use a recent version of PySide2, the problem doesn't present at all, since it already supports that naming pattern. For [very] future reference, always check for supported features when dealing with major versions that are pretty new: Qt6 has been released less than 9 months ago (which is not a lot for a huge toolkit like Qt is), and many features of Qt5 have been temporarily removed until they're considered mature.

现在,@Lino的PyQt6和5几乎没有什么不同,除非你在使用Qt6中添加的特定新特性,否则唯一的大区别就是枚举的用法。此外,如果您使用最新版本的PySide2,则AFAIK根本不会出现该问题,因为它已经支持该命名模式。对于[非常]未来的参考,在处理相当新的主要版本时,始终检查支持的功能:Qt6发布不到9个月(对于Qt这样的大型工具包来说,这并不是很多),Qt5的许多功能已经被临时删除,直到它们被认为是成熟的。

优秀答案推荐

qasync does not currently support PyQt6 but I have created a PR that implements it.

Qasync目前不支持PyQt6,但我已经创建了一个实现它的PR。


At the moment you can install my version of qasync using the following command:

目前,您可以使用以下命令安装我的qasync版本:


pip install git+https://github.com/eyllanesc/qasync.git@PyQt6

Probably in future releases my PR will be accepted so there will already be support for PyQt6

可能在将来的版本中,我的PR将被接受,因此将会有对PyQt6的支持


They already accepted my PR so you can already install the latest version of qasync that has support for PyQt6.

他们已经接受了我的PR,所以你已经可以安装支持PyQt6的最新版本的qasync了。



os.environ.setdefault("QT_API", "PyQt6")
from asyncqt import QEventLoop

更多回答

Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?

请记住,Stack Overflow不仅仅是为了解决眼前的问题,也是为了帮助未来的读者找到类似问题的解决方案,这需要理解底层代码。这对于我们社区的初学者和不熟悉语法的成员来说尤其重要。考虑到这一点,你能编辑你的答案,包括你正在做的事情的解释以及为什么你认为这是最好的方法吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com