python - What is the asterisk for in signal and slot connections? -
in python qt, i'm connecting qlistwidget signal slot, this:
qtcore.qobject.connect(self.mylist, qtcore.signal("itemclicked(qlistwidgetitem *)"), self.listeventhandler)
my question is: trailing asterisk in qlistwidgetitem *
do?
a couple of bullet points explain (i'll try avoid c++ syntax):
- pyqt python wrapper around qt, written in c++.
- qt provides introspection classes inheriting
qobject
, using strings identify things. python has native introspection, c++ not. - the syntax used called "old-style signals , slots", uses c++ function signatures.
- c++ has more types of variables python. in c++, variable can value, reference, or pointer. pointers have asterisk after type name.
qtcore.signal("itemclicked(qlistwidgetitem *)")
refers qt signal calleditemclicked
has parameter pointerqlistwidgetitem
, not item itself.
in c++, looks like:
void itemclicked(qlistwidgetitem *item);
going strings introspection, identify signal or slot, drop void
, ;
, , variable name (item
), leaving:
itemclicked(qlistwidgetitem *)
wrap above in qtcore.signal()
, pair of quotes , have:
qtcore.signal("itemclicked(qlistwidgetitem *)")
what pointer?
there number of questions this. here one number of analogies in answers simplify things you.
if old-style syntax, what's new style?
frodon bringing up. pyqt has more "pythonic" method of connecting signals slots, in format:
object.signalname.connect(otherobject.slotname)
in case:
self.mylist.itemclicked.connect(self.listeventhandler)
read more in docs.
Comments
Post a Comment