[Interest] Does removing 'private slots' from .h files have any advantages? Disadvantages?

Bo Thorsen bo at vikingsoft.eu
Wed Mar 11 11:13:36 CET 2015


Den 08-03-2015 kl. 11:58 skrev Guido Seifert:
> I am just curious. In one of my old projects I replaced all SIGNAL/SLOT connections with the newer function pointer api.
> In theory I now could remove all the 'public/protected/private slot' markers from my .h files. Now I am wondering, if this
> is only cosmetic, or does it have any advantages/disadvantages? Faster compile time? Smaller executables?

Hi Guido,

I think the main disadvantage in this is that it would surprise Qt 
developers. There is knowledge in you writing "slots" in the .h file, 
just like there is in using emit.

Personally, I don't use this feature much. The parts of the new connect 
that I use is the new connect syntax for compile time checked connects 
and lambdas.

Instead of considering whether I should write "slot" in the .h file, I 
try to make the public parts of my class smaller using the new 
approaches. This gives me fewer changes to the header files as I work 
with them, which brings down recompile time.

One example of a useful conversion is in network code. If you have a 
class that sends multiple http requests, in Qt 4 you might have a 
private slot that uses sender(). With the lambda approach, you get rid 
of a private slot and remove the need for the slightly obnoxious use of 
sender(). IMO changes like this gives you real advantages instead of 
just cosmetic changes.

Bo.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu




More information about the Interest mailing list