[PyQt] pyqtsignal() and None value
maurizio.berti at gmail.com
Tue Sep 4 18:08:45 BST 2018
You are defining a specific signature in the signal:
this means that, despite the types you set in the method (which Qt doesn't
know anything of also, as you didn't use the Slot decorator), whenever you
emit a None (which is a NoneType, not int, nor str) Qt will try to
"translate" it to the valid signature you assigned.
I don't know exactly why the int is that a high number (always high and
always random), but this probably makes sense for some C++ type signature,
as it seems to me that the number is always 32bit long and, in my case,
Anyway, if you really need to send None, you can use the generic "object"
signature in the signal definition, or, in your case, just go with this,
assuming the progress will never use negative numbers.
def updateProgress(self, val: int=-1, text: str=''):
if val is >= 0:
and then emit the text signal using -1 for val.
2018-09-04 18:16 GMT+02:00 J Barchan <jnbarchan at gmail.com>:
> PyQt5.7. I am having trouble `emit()`ing a signal and receiving its
> arguments correctly. I have read http://pyqt.sourceforge.net/
> Docs/PyQt5/signals_slots.html carefully.
> # class variable for "notifyProgress" signal, for displaying a
> notifyProgress = QtCore.pyqtSignal(int, str)
> def updateProgress(self, val: int, text: str):
> # slot for self.notifyProgress
> # eprpayrequestfunctions.runEpr() calls this to indicate progress
> # if it passes an integer it's the desired value for the
> # if it passes a string it's the desired value for the label
> if val is not None:
> if text is not None:
> 1. notifyProgress.emit(None, "Some text")
> 2. notifyProgress.emit(i / 2, None)
> *Behaviour in slot*:
> The problem is the passing of None from emit():
> 1. val arrives in slot as 1261196128.
> 2. text arrives in slot as '' (empty string).
> - Where is this behaviour for None as an emit() parameter documented?
> - What is the correct/best way for handling this correctly/easily?
> PyQt mailing list PyQt at riverbankcomputing.com
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt