PDA

View Full Version : not able to receive SIGNAL



thefriedc
27th September 2010, 21:16
hi,

i've got a QWidget with some lineedits, a "cancel" button and an "apply" button.

i connect the "clicked()" signal to the QWidget like this:



self.connect(self.__apply_button, QtCore.SIGNAL("clicked()"), QtCore.SIGNAL("apply_clicked"))
self.connect(self.__cancel_button, QtCore.SIGNAL("clicked()"), QtCore.SIGNAL("cancel_clicked"))


when ths signal is sent, i want to forward a signal to the parent of the QWidget (__mywidget) which is of the type QObject.

at the parent i listen to the signals of my QWidget



self.connect(self.__mywidget, QtCore.SIGNAL("apply_clicked"), self.__handle_apply)
self.connect(self.__mywidget, QtCore.SIGNAL("cancel_clicked"), self.__handle_cancel)


the problem is, i never receive the signal from __mywidget. __handle_apply and __handle_cancel are custom slots of course

i also tried to emit a signal manually from __mywidget but it doesn't work either.

NOTE: please consider this is python syntax. should be syntactically ok.

any ideas? what do i have to consider when connecting to signals?
i'm completely clueless, what im doing wrong there.

thanks, chris

wysota
27th September 2010, 22:10
QObject does not have a "apply_clicked" signal. You should subclass QObject and introduce the method in the subclass.

thefriedc
27th September 2010, 23:30
i'm sorry, i did not clearly mention, that __mywidget is a subclass of QWidget and the parent is a subclass of QObject

apply_clicked is my own defined signal. i don't know the exact differences between Qt for c++ and PyQt when it comes to signals, but it is possible to define your own signals that way

any other ideas?

wysota
27th September 2010, 23:47
There are SLOT macros missing in your connect statements.

thefriedc
28th September 2010, 08:34
i'm sorry - there are no slot macros in pyqt (at least i don't know them :o) - the connect statements are totally correct for pyqt.

the problem was the way i did instantiate the parent class QObject. i'm kinda new to python and there are obviously several ways to inherit from classes. although i had access to inherited methods ... the SIGNAL handling did not work when inherited like this:


class ViewController(QtCore.QObject):

def __init__(self, parent=None):
QtCore.QObject.__init__(self)

a strange thing is, that it already works in another class when i instantiate this way but i cannot get it working here ...

-> changing to this is the solution of the problem:

class ViewController(QtCore.QObject):

def __init__(self, parent=None):
super(ViewController, self).__init__(parent)

so the problem is solved ... at least the SIGNAL thing.
thanks anyway