[cython/cython] [BUG] Cython has problems recognizing signals from PyQt6. (Issue #5910)

0 views
Skip to first unread message

Jasper James

unread,
Dec 15, 2023, 2:17:11 AM12/15/23
to cython/cython, Subscribed

Describe the bug

A common button signal and slot function in PyQt6 has problems when compiled with cython. (The original py file works fine)

Code to reproduce the behaviour:

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')

Expected behaviour

  1. In the original py file, the minimal example shown above performs the function inside the get_path method when the button is clicked.

  2. I use cythonize -i -3 ProjectDialog.py to compile the py file.

  3. 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)

  4. 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)
  1. i would like to know why cython is causing this?

OS

Windows 11 Professional

Python version

Python 3.12.0

Cython version

Cython version 3.0.6

Additional context

No response


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <cython/cython/issues/5910@github.com>

da-woods

unread,
May 21, 2024, 12:36:17 PM5/21/24
to cython/cython, Subscribed

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.Message ID: <cython/cython/issues/5910/2123018618@github.com>

Reply all
Reply to author
Forward
0 new messages