[Interest] Problem about signals/slots in Qt 5

Thiago Macieira thiago.macieira at intel.com
Wed Sep 19 01:12:10 CEST 2012

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); });

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120919/49b9a820/attachment.sig>

More information about the Interest mailing list