A common button signal and slot function in PyQt6 has problems when compiled with cython. (The original py file works fine)
class ProjectDialog(QDialog, Ui_project_dialog_layout): def __init__(self): super().__init__() self.setupUi(self) self.dir_button.clicked.connect(self.get_path) def get_path(self): # do something print('work well')
In the original py file, the minimal example shown above performs the function inside the get_path method when the button is clicked.
I use cythonize -i -3 ProjectDialog.py to compile the py file.
Call the class ProjectDialog compiled by cython, and the following error message appears after executing the button clicking function:
Traceback (most recent call last):
File "ProjectDialog.py", line 55, in ProjectDialog.get_path
TypeError: get_path() takes exactly 1 positional argument (2 given)
I found two solutions for this case, one is to add a parameter to the get_path method to accept the bool value emitted by PyQt6's clicked signal, and the other is to use a lambda function:
class ProjectDialog(QDialog, Ui_project_dialog_layout):
def init(self):
super().init()
self.setupUi(self)
self.project_fullname = ''
self.dir_button.clicked.connect(self.get_path)
def get_path(self, click_status):
path = xqt_dir_open(self)
if xqt_dir_isexist(path):
self.project_home_edit.setText(path)
class ProjectDialog(QDialog, Ui_project_dialog_layout):
def init(self):
super().init()
self.setupUi(self)
self.project_fullname = ''
self.dir_button.clicked.connect(lambda: self.get_path())
def get_path(self):
path = xqt_dir_open(self)
if xqt_dir_isexist(path):
self.project_home_edit.setText(path)
Windows 11 Professional
Python 3.12.0
Cython version 3.0.6
No response
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I'm relatively convinced that this is a bug in PyQt6 (and that it internally relies on being passed a Python function, therefore is incompatible pretty much by definition) and thus there's nothing Cython can do to fix this. But I'm not absolutely certain and it's fairly difficult to investigate.
Qt code doesn't usually benefit from being processed by Cython. And we aren't hugely interested in supporting obfuscation (which is the main reason that people want to do it).
So it'll probably only get fixed if someone else wants to investigate and propose a fix (either to Cython, or more likely to PyQt6).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()