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

Guido Seifert wargand at gmx.de
Wed Mar 11 11:58:04 CET 2015


 
> Hi Guido,

Hi back :-)
 
> 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.

Yes, but if there was a compelling reason not to use 'slots' I would mark
my slots, but comment the mark out, e.g.:

// private slots:

I too like to see on one glance, which method might be executed by a signal,
and which not.
 
> 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.

I really love the compile time checks. Sure, I can (and often did) check the
return value of connect, but it can be a certain hassle to make sure that during tests
really all code paths and really all connects are covered and really nowhere a connection
is skipped due to a typing error. Compile time error detection always beats run time error
detection. For me this alone is reason enough to use the new syntax and never look back.

Also much easier to change signal/slot parameters if necessary. 

> 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 does not exclude the other. ;-)

> 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.

Yes. But my question was if removing the slot macros really is only a pure cosmetic change, or not.
Apparently the difference is only minimal in the one or the other direction that one does not need
to bother. For now I decided to keep the slot macros for better readability in.

Guido





More information about the Interest mailing list