[PyQt] pyqtsignal() and None value
Maurizio Berti
maurizio.berti at gmail.com
Tue Sep 4 18:08:45 BST 2018
You are defining a specific signature in the signal:
QtCore.pyqtSignal(int, str)
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,
always negative.
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:
self.progressBar.pb.setValue(val)
if text:
self.progressBar.label.setText(text)
and then emit the text signal using -1 for val.
Maurizio
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.
>
> *Declaration*:
>
> # class variable for "notifyProgress" signal, for displaying a
> progressbar
> notifyProgress = QtCore.pyqtSignal(int, str)
>
> *Initialisation*:
>
> self.notifyProgress.connect(self.updateProgress)
>
> *Slot*:
>
> 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
> progressbar
> # if it passes a string it's the desired value for the label
> if val is not None:
> self.progressBar.pb.setValue(val)
> if text is not None:
> self.progressBar.label.setText(text)
>
> *Signals*:
>
> 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).
>
> *Questions*:
>
> - Where is this behaviour for None as an emit() parameter documented?
> - What is the correct/best way for handling this correctly/easily?
>
>
> --
> Kindest,
> Jonathan
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
--
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180904/233686e6/attachment-0001.html>
More information about the PyQt
mailing list