Results 1 to 6 of 6

Thread: [PyQt] send and emit an customer class....

  1. #1
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: [PyQt] send and emit an customer class....

    Hello everybody,

    I do have a problem with the signal/slot stuff.....

    Qt Code:
    1. class Test(QObject):
    2. def __init__(self, parent=None):
    3. QObject.__init__(self, parent)
    4. self.connect(self, SIGNAL('send(int)'), self, SLOT('receiver(int)'))
    5.  
    6. def send(self, value):
    7. self.emit(SIGNAL('send(int)'), value)
    8.  
    9. @pyqtSignature('receiver(int)')
    10. def receiver(self, value):
    11. print value
    12.  
    13.  
    14. def main():
    15. test = Test()
    16. test.send(12345)
    17.  
    18.  
    19. app = QtGui.QApplication(sys.argv)
    20. Start = main()
    21. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Here you can see my very simple code... I have a class called Test.... I want that this class emits a signal and the same class receives this signal.
    As the code is written above everything is fine....

    Now I want to emit not a integer variable. I want to emit and receive a customer class... I simply changed int everywhere to my classes name and tried to run this code...
    Here is how I did it....my customer class and the new code...

    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4 import QtGui
    3. import sys
    4.  
    5. class Student:
    6. def __init__(self, name, Studium, Nr):
    7. self.name = name
    8. self.Fach = Studium
    9. self.Matrikel = Nr
    10.  
    11.  
    12.  
    13. class Test(QObject):
    14. def __init__(self, parent=None):
    15. QObject.__init__(self, parent)
    16. self.connect(self, SIGNAL('send(Student)'), self, SLOT('receiver(Student)'))
    17.  
    18. def send(self, value):
    19. self.emit(SIGNAL('send(Student)'), value)
    20.  
    21. @pyqtSignature('receiver(Student)')
    22. def receiver(self, value):
    23. print value
    24.  
    25.  
    26. def main():
    27. #Andi = Student("Andi", "MB", 23523)
    28. test = Test()
    29. test.send(Student('Andi', 'MB',12345))
    30.  
    31.  
    32. app = QtGui.QApplication(sys.argv)
    33. Start = main()
    34. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    The failure message is:
    Traceback (most recent call last):
    File "C:\Dokumente und Einstellungen\faankesk\Desktop\test\test.py", line 13, in <module>
    class Test(QObject):
    File "C:\Dokumente und Einstellungen\faankesk\Desktop\test\test.py", line 21, in Test
    @pyqtSignature('receiver(Student)')
    TypeError: C++ type 'Student' is not supported as a pyqtSlot signature argument type
    #---------------------------------------------

    Does anybody know why this doesn't work? I don't see the problem....
    I hope you understood my problem....
    Thank you for helping

    Cascoin


    Added after 27 minutes:


    by the way I use Qt 4.7.1
    Last edited by cascoin; 6th June 2011 at 12:53.

  2. #2
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [PyQt] send and emit an customer class....

    Please replace "Student" with "PyQt_PyObject" in signals and slots.
    You can refer to: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/old_style_signals_slots.html

    You'd better replace this old-fashioned signals and slots usage with the new .
    Please refer to: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html

  3. #3
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: [PyQt] send and emit an customer class....

    Hi,
    thank you for your answer...
    I read the documentation about "New Signal and Slot"-stuff about hundret times...
    But I don't understand how to change my example...

    I just want to replace my signal. I DONT want to send just an "int"-variable...
    I want to send a customer-data... Like the student-data-typ in my example...

    Can anybody please give me a hint how to start? I tried it very often but it doesn't work...

    thanks a lot,

    Cascoin

  4. #4
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: [PyQt] send and emit an customer class....

    please help me if you can!

  5. #5
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: [PyQt] send and emit an customer class....

    Qt Code:
    1. self.connect(self, SIGNAL('send(PyQt_PyObject)'), self, SLOT('receiver(PyQt_PyObject)'))
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2013
    Posts
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: [PyQt] send and emit an customer class....

    If I have understood your problem correctly. You could try short-circuit signal to pass your custom python object as your signal paramter. emiting as: self.emit(SIGNAL("send"), value) , and connect as self.connect(self, SIGNAL("send"), self.receiver)

Similar Threads

  1. Upgrading from PyQt 4.5 to PyQt 4.7
    By RogerCon in forum Installation and Deployment
    Replies: 0
    Last Post: 14th July 2010, 18:52
  2. Create Own Signal send to different class
    By arpspatel in forum Qt Programming
    Replies: 0
    Last Post: 5th April 2010, 23:46
  3. Replies: 3
    Last Post: 27th December 2008, 19:34
  4. send own class reference throught signal
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2008, 21:55
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.