简体   繁体   English

在Cython中使用pyqt类(.pyx文件)

[英]use pyqt classes in Cython(.pyx file)

How to use pyqt classes in Cython(.pyx file)? 如何在Cython(.pyx文件)中使用pyqt类?
In fact, how can pyqt classes be inherited in cython classes? 实际上,如何在cython类中继承pyqt类?

thank you 谢谢

All Python code should be valid Cython code (there are bugs, so this isn't quite true, but it's close). 所有Python代码都应该是有效的Cython代码(有bug,所以这不太正确,但它很接近)。 Therefore Python code using PyQt should work as it is under Cython and if it doesn't then you should report it to the Cython bugtracker. 因此,使用PyQt的Python代码应该在Cython下工作,如果没有,那么你应该将它报告给Cython bugtracker。 However, in the past people have reported problems because PyQt uses multiple threads but Cython does not release the GIL regularly. 但是,过去人们报告了问题,因为PyQt使用多个线程,但Cython不会定期发布GIL。 Therefore you might find that your application hangs and it is not possible to combine PyQt and Cython. 因此,您可能会发现应用程序挂起,并且无法组合PyQt和Cython。


Cython has no special access to PyQt classes therefore you should not cdef them - just treat them as normal Python variables. Cython没有对PyQt类的特殊访问权限,因此你不应该对它们进行cdef - 只需将它们视为普通的Python变量即可。

Because of this lack of special access you cannot inherit from them in a cdef class . 由于缺少特殊访问权限,您无法在cdef class继承它们。 However they work fine when you inherit from in a normal class. 但是,当您从普通类继承时,它们可以正常工作。


In general there is no benefit to trying to set cdef types for regular Python objects (including PyQt classes); 通常,尝试为常规Python对象(包括PyQt类)设置cdef类型没有任何好处; just write the code as if it was Python. 只需编写代码就像是Python一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM