[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] pyqt4 signal/slot using PyObject* and shortcut
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2007-04-27 15:19:37
Message-ID: 200704271619.37144.phil () riverbankcomputing ! co ! uk
[Download RAW message or body]

On Friday 27 April 2007 3:45 pm, Andreas Pakulat wrote:
> On 27.04.07 11:30:04, Pradnyesh Sawant wrote:
> >    def run(self):
> >        cntr = 0
> >        while cntr < 10:
> >            cntr += 1
> >            self.emit(QtCore.SIGNAL("showCntr1(PyObject*)"), (cntr,
> > "a"))   # line 1
> >            self.emit(QtCore.SIGNAL("showCntr2"), (cntr, "a"))
> >          # line 2
> >            time.sleep(0.2)
>
> ...
>
> > if __name__ == "__main__":
> >    app = QtGui.QApplication(sys.argv)
> >    dialog = Gui()
> >    cntr = Counter()
> >    cntr.start()
> >    QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr1(PyObject*)"),
> >            dialog.showCntr1, QtCore.Qt.QueuedConnection)
> >    QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr2"),
> >            dialog.showCntr1, QtCore.Qt.QueuedConnection)
> >    sys.exit(dialog.exec_())
> > #################################################################
> > If i comment out "line 1", then i get the following output:
>
> You don't keep a reference to the object that you send via the signal.
> You need to do that, as a queued connection behaves different from a
> direct connection (which is a direct function call). Thats why you see
> all kinds of weird results.

Sorry, but that's wrong. PyQt handles the reference counts of arguments to 
shortcircuit signals automatically.

> I couldn't make the line 1 work though, it always tells me that argument
> 0 of the signal has an invalid type.

Because you need to use PyQt_PyObject instead of PyObject * (which never 
worked properly).

All of the original poster's problems are down to using an old version of 
PyQt4.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic