Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting compliation error in using connect in pyqt4



  • I have 2 objects in a class

    QtCore.QObject.connect(self.voTreeView,QtCore.SIGNAL("copySignal(list)"),self.metricsTreeView,QtCore.SLOT(self.metricsTreeView.clipboardData))

    I have my own customised signal and I want to send the list from one object to other object

    I am getting following error

    QtCore.QObject.connect(self.voTreeView,QtCore.SIGNAL("copySignal(list)"),self.metricsTreeView,QtCore.SLOT(self.metricsTreeView.clipboardData))
    TypeError: SLOT(str): argument 1 has unexpected type 'instancemethod'

    Could you please let me know how correct the compilation issue


  • Banned

    Can you supply an MRE (Minimal Reproducible Example) so that we can just copy/paste and run and see the error otherwise the answer we provide to the favor you are requesting may be completely wrong as we cannot actually troubleshoot this issue of yours.

    Ultimately in the end help us help you with your problem



  • @Qt-Enthusiast said in Getting compliation error in using connect in pyqt4:

    QtCore.QObject.connect(self.voTreeView,QtCore.SIGNAL("copySignal(list)"),self.metricsTreeView,QtCore.SLOT(self.metricsTreeView.clipboardData))
    TypeError: SLOT(str): argument 1 has unexpected type 'instancemethod'
    

    Your QtCore.SIGNAL("...")correctly takes a string parameter. In your QtCore.SLOT(self.metricsTreeView.clipboardData) you are passing a method/callable instead of a string. Doesn't QtCore.SLOT() require a string like QtCore.SIGNAL() does? I suspect you intend:

    QtCore.QObject.connect(self.voTreeView, QtCore.SIGNAL("copySignal(list)"), self.metricsTreeView, self.metricsTreeView.clipboardData)
    

    You probably already know that you would benefit from moving to PyQt5. But even later versions of PyQt4 introduced support for new-style signal/slots, which would have helped here. Is this legacy code which is no longer actively developed?



  • https://paste.ofcode.org/eG2QgwngRbwJdq933jdKS3

    Not working . Can u some one tell the solution

    1.png t](image url)



  • @Qt-Enthusiast
    Since your latest code paste uses new-style signal/slot syntax for connect(), why did you bother asking about your old-style QtCore.QObject.connect(...) code?



  • @Qt-Enthusiast
    In your pasted code:

    t1.mysignal = QtCore.pyqtSignal(list)
    

    How is this setting a class variable? It is setting an instance variable, while you need it to be a class variable in class Test.


Log in to reply