信号槽问题

Python中的任意函数都可以作为槽函数使用而无需使用@Slot装饰器,只要它符合与信号连接的规则(参数对应上),使用@Slot显示地声明可以提高效率,而不需要Python去隐式地转换类型。

python - Is the PySide Slot Decorator Necessary? - Stack Overflow

另一篇文章Should I decorate slots in Pyside2 and if so how?的回答:

As to whether you should decorate the slots, it’s a little trickier to answer – but generally speaking no, you don’t need to.

The only place I know the slot decorator is needed is when a) using threads, as it ensures the decorated method is started in the correct thread, or b) when you want to explicitly map a given slot to a specific call signature (types) in C++.

In your examples, the slots are running in the GUI thread and signal/slots are single-typed, so you don’t need them.

多线程API问题

PyQt年代已有的讨论:multithreading - Threading in a PyQt application: Use Qt threads or Python threads? - Stack Overflow,结论是:

Although there’s no 100% agreement, there seems to be widespread consensus that the answer is “use Qt”, since the advantage of that is integration with the rest of the library, while causing no real disadvantages.

It’s mostly the same. The main difference is that QThreads are better integrated with Qt (asynchrnous signals/slots, event loop, etc.). Also, you can’t use Qt from a Python thread (you can’t for instance post event to the main thread through QApplication.postEvent): you need a QThread for that to work.

A general rule of thumb might be to use QThreads if you’re going to interact somehow with Qt, and use Python threads otherwise.

在VSCode里若要调试QThread,需要添加少量代码:

Debugging configurations for Python apps in Visual Studio Code

If you’re working with a multi-threaded app that uses native thread APIs (such as the Win32 CreateThread function rather than the Python threading APIs), it’s presently necessary to include the following source code at the top of whichever file you want to debug:

import debugpy
debugpy.debug_this_thread()