<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 5 September 2018 at 09:11, J Barchan <span dir="ltr"><<a href="mailto:jnbarchan@gmail.com" target="_blank">jnbarchan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif"><br></div><div class="gmail_extra"><div><div class="gmail-h5"><br><div class="gmail_quote">On 4 September 2018 at 18:08, Maurizio Berti <span dir="ltr"><<a href="mailto:maurizio.berti@gmail.com" target="_blank">maurizio.berti@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">You are defining a specific signature in the signal:</div><div dir="ltr"><span style="font-family:monospace,monospace;font-size:12.8px"><br></span></div><div dir="ltr"><span style="font-family:monospace,monospace;font-size:12.8px"><div style="font-family:tahoma,sans-serif;display:inline" class="gmail_default"></div>QtCore.pyqtSignal(int, str)</span><br></div><br>this means that, despite the types you set in the method <div style="font-family:tahoma,sans-serif;display:inline"></div>(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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div><span style="font-family:monospace,monospace;font-size:12.8px">def updateProgress(self, <div style="font-family:tahoma,sans-serif;display:inline"></div><div style="font-family:tahoma,sans-serif;display:inline"></div>val: int=-1, <div style="font-family:tahoma,sans-serif;display:inline"></div>text: str=''):</span><br></div><span style="font-family:monospace,monospace;font-size:12.8px"> </span><span style="font-family:monospace,monospace;font-size:12.8px">if val is >= 0:</span><br style="font-family:monospace,monospace;font-size:12.8px"><span style="font-family:monospace,monospace;font-size:12.8px"> </span><span style="font-family:monospace,monospace;font-size:12.8px"> self.progressBar.pb.setValue(</span><span style="font-family:monospace,monospace;font-size:12.8px">v<wbr>al)</span><br style="font-family:monospace,monospace;font-size:12.8px"><span style="font-family:monospace,monospace;font-size:12.8px"> </span><span style="font-family:monospace,monospace;font-size:12.8px">if text:</span><br style="font-family:monospace,monospace;font-size:12.8px"><div><span style="font-family:monospace,monospace;font-size:12.8px"> </span><span style="font-family:monospace,monospace;font-size:12.8px"> </span><span style="font-family:monospace,monospace;font-size:12.8px"> self.progressBar.label.</span><span style="font-family:monospace,monospace;font-size:12.8px">setText<wbr>(text)</span> </div><div dir="ltr"><br></div><div>and then emit the text signal using -1 for val.</div><div dir="ltr"><br></div><div>Maurizio</div><div dir="ltr"><br></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-m_1169979402024537463h5">2018-09-04 18:16 GMT+02:00 J Barchan <span dir="ltr"><<a href="mailto:jnbarchan@gmail.com" target="_blank">jnbarchan@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_1169979402024537463h5"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-family:tahoma,sans-serif">PyQt5.7. I am having trouble `emit()`ing a signal and receiving its arguments correctly. I have read<div style="font-family:tahoma,sans-serif;display:inline"></div> <a href="http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html" target="_blank">http://pyqt.sourceforge.net/Do<wbr>cs/PyQt5/signals_slots.html</a> carefully.<br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><b>Declaration</b>:</div><br><div style="font-family:tahoma,sans-serif"><span style="font-family:monospace,monospace"> # class variable for "notifyProgress" signal, for displaying a progressbar<br> notifyProgress = QtCore.pyqtSignal(int, str)</span><br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><b>Initialisation</b>:</div><div style="font-family:tahoma,sans-serif"><br></div><div><span style="font-family:monospace,monospace"> self.notifyProgress.connect(se<wbr>lf.updateProgress)</span></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><b>Slot</b>:</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><span style="font-family:monospace,monospace"> def updateProgress(self, val: int, text: str):<br> # slot for self.notifyProgress<br> # eprpayrequestfunctions.runEpr(<wbr>) calls this to indicate progress<br> # if it passes an integer it's the desired value for the progressbar<br> # if it passes a string it's the desired value for the label<br> if val is not None:<br> self.progressBar.pb.setValue(v<wbr>al)<br> if text is not None:<br> self.progressBar.label.setText<wbr>(text)</span><br><br></div><div style="font-family:tahoma,sans-serif"><b>Signals</b>:</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><span style="font-family:monospace,monospace">1. notifyProgress.emit(None, "Some text")<br><br>2. notifyProgress.emit(i / 2, None)</span></div><br><div style="font-family:tahoma,sans-serif"><b>Behaviour in slot</b>:<br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">The problem is the passing of <span style="font-family:monospace,monospace">None</span> from <span style="font-family:monospace,monospace">emit()</span>:</div><div style="font-family:tahoma,sans-serif"><br></div>1. <span style="font-family:monospace,monospace">val</span> arrives in slot as <span style="font-family:monospace,monospace">1261196128</span>.<div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><div>2. <span style="font-family:monospace,monospace">text</span> arrives in slot as <span style="font-family:monospace,monospace">''</span> (empty string).</div><div><br></div><div></div><b>Questions</b>:</div><div style="font-family:tahoma,sans-serif"><ul><li>Where is this behaviour for <span style="font-family:monospace,monospace">None</span> as an <span style="font-family:monospace,monospace">emit()</span> parameter documented?</li><li>What is the correct/best way for handling this correctly/easily?<span class="gmail-m_1169979402024537463m_-2805916086382413410HOEnZb"><font color="#888888"><br></font></span></li></ul></div></div><span class="gmail-m_1169979402024537463m_-2805916086382413410HOEnZb"><font color="#888888"><div dir="ltr"><br>-- <br><div class="gmail-m_1169979402024537463m_-2805916086382413410m_6813107041399019673gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</div></font></span></div></div></div></div></div></div>
<br></div></div>______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing<wbr>.com/mailman/listinfo/pyqt</a><span class="gmail-m_1169979402024537463HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="gmail-m_1169979402024537463HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="gmail-m_1169979402024537463m_-2805916086382413410gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</font></span></div>
</blockquote></div><br></div></div><div style="font-family:tahoma,sans-serif">I'm OK with the <span style="font-family:monospace,monospace;font-size:12.8px"><div style="font-family:tahoma,sans-serif;display:inline"></div>val: int=-1</span>, but not with the <span style="font-family:monospace,monospace;font-size:12.8px"><div style="font-family:tahoma,sans-serif;display:inline"></div>text: str=''</span>. An <span style="font-family:monospace,monospace">int</span> of <span style="font-family:monospace,monospace">-1</span> is happily an invalid value for me, butt the trouble is a <span style="font-family:monospace,monospace">str</span> of <span style="font-family:monospace,monospace">''</span> is perfectly legal, and will be used :(</div><span class="gmail-"><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><div style="display:inline"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">(which Qt doesn't know anything of also, as you didn't use the Slot decorator),<br></blockquote></div><div style="font-family:tahoma,sans-serif"><br></div></span><div style="font-family:tahoma,sans-serif">I don't mind adding a slot decorator if that would help. But presumably it would not here, as you're saying my <span style="font-family:monospace,monospace">None</span> value does not match the type correctly anyway, right?</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">I did consider making it so there is only one parameter, and the type (<span style="font-family:monospace,monospace">int</span> or <span style="font-family:monospace,monospace">str</span>) indicates which of the two paths to follow in the slot. I followed <div style="display:inline"></div> <a href="http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html" target="_blank">http://pyqt.sourceforge.net/Do<wbr>cs/PyQt5/signals_slots.html</a> carefully where it describes"The following code demonstrates the connection of overloaded signals:" but I couldn't get it to work: it <i>always</i> called the first/default overload, regardless of the parameter type ... :(</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">I'm now thinking: could I cut my losses and pass (and receive?) a single parameter as an explicit <span style="font-family:monospace,monospace">QVariant</span> (which we don't usually use from PyQt), so that a single receiver slot can correctly see the original type --- would that work/be advisable?<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></div><span class="gmail-HOEnZb"><font color="#888888"><br clear="all"><br>-- <br><div class="gmail-m_1169979402024537463gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</font></span></div></div>
</blockquote></div><br><div style="font-family:tahoma,sans-serif" class="gmail_default">OK, I gave <span style="font-family:monospace,monospace">QVariant</span> (single parameter) a try. <i>All</i> I had to was:</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">1. Declare signal as:</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default"> <span style="font-family:monospace,monospace">QtCore.pyqtSignal(QVariant)</span></div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">2. Write slot like:</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div class="gmail_default"><span style="font-family:monospace,monospace">def updateProgress(self, val):<br> if type(val) is int or type(val) is float:<br> self.progressBar.pb.setValue(val)<br> elif type(val) is str:<br> self.progressBar.label.setText(val)</span></div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">3. And then it works correctly with both emitter types (without caller bothering with <span style="font-family:monospace,monospace">QVariant</span>), like:</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div class="gmail_default"><span style="font-family:monospace,monospace">notifyProgress.emit(50)<br>notifyProgress.emit("Finishing...")</span></div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Is there any reason I should <i>not</i> be doing this, because it seems perfect to me?<br></div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</div></div></div></div></div>