[Interest] Are slots even needed these days?

Alejandro Exojo suy at badopi.org
Thu Mar 17 07:08:20 CET 2016


El Wednesday 16 March 2016, Alexander Görtz escribió:
> Yeah wanted to say the same here, the line to connect to a QSpinBox 
> valueChanged is really realy ugly. Mostly because of the ugly syntax of 
> pointers to member functions.

A helper function, qOverload, was added to mitigate this (in 5.7):

http://doc-snapshots.qt.io/qt5-5.7/qtglobal.html#qOverload

Anyway, you can make it decent enough if you organize a bit with an 
intermediate typedef:

using valueChangedSignal = void(QSpinBox::*)(int);
auto valueChangedPointer =
		static_cast<valueChangedSignal>(&QSpinBox::valueChanged);
connect(ui->cacheSize, valueChangedPointer,
		this, &SyncWidget::changeCacheLimits);
connect(ui->cacheAge, valueChangedPointer,
		this, &SyncWidget::changeCacheLimits);

If you really really need the overloads, and you use them in connections a 
lot, maybe you could even provide the typedef (and the pointer, if you don't 
think it's too much) in your own classes.

-- 
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net



More information about the Interest mailing list