[Interest] Problem about signals/slots in Qt 5

Stephen Chu stephen at ju-ju.com
Wed Sep 19 01:59:44 CEST 2012

On 9/18/12 7:12 PM, Thiago Macieira wrote:
> On terça-feira, 18 de setembro de 2012 18.40.28, Stephen Chu wrote:
>> On 9/18/12 8:30 AM, Josiah Bryan wrote:
>>> I agree! I can't tell you how many times I've checked and rechecked my
>>> code, only to find out it was a sig/slot mismatch all along. Crikey! :-)
>> The only problem I have with the new syntax is it doesn't handle the
>> case when the slot require more arguments than the signal but the extra
>> arguments in the slot are all default arguments.
>> For example, I can't connect my signal showMessage(QString) to
>> QStatusBar::showMessage(QString, int=0) this way. I'll get a static
>> assert "The slot requires more arguments than the signal provides."
> The C++ language doesn't allow that. Default arguments only show up when
> you're calling a function directly. The moment that you take the address and
> put it in a function pointer, they aren't visible anymore.
> To complete that connection, you need a lambda:
> QObject::connect(sender, &MyClass::showMessage,
> 	[=](const QString &s) { statusBar->showMessage(s); });

OMG. Thiago. You just made my day (or night). I completely forgot about 
lambda closure.

This probably makes QSignalMapper obsolete.

More information about the Interest mailing list