Search code examples
c++qtqt4signals-slots

List the drawback (performance/maintenance etc.,) in having all setter functions as SLOTS in Qt?


Is there any drawback (performance/maintenance etc.,) in having all setter functions as SLOTS in Qt?

Some of the disadvantages i see are,

1) Unnecessary call of MOC and Unnecessary moc files created during compile time 2) Break in the exception handling chain, since exceptions are not passed in signal-slot connection 3) Unnecessary complexity in debugging, since it is harder to debug with signal-slot thatn direct method call.

Can you list any other disadvantages (if any)?


Solution

  • If you call the setters directly, you can avoid most of the drawbacks you mention. It will behave as any other normal call. The only drawback in that case would be the longer compiler time and bigger bin size.

    If you call all your setters by emitting signals, then:

    1) More complex code; since you have to remember to connect all your signals to all your slots for every set.

    2) Small performance hit. It would be negligible for any GUI app; but its there.

    3) Less deterministic code. I.e. depending on the way the signals are connected, the call might be passed directly to the callee, or sent through an event system. This further complicates debugging, besides what you've mentioned already.

    4) IDE issues. If you are not using QtCreator or KDevelop, the IDE might not understand the special keywords (slot, signal, emit).

    Except for (1), all these issues are minor. But the main reason for not doing this, I say, would be it doesn't make sense. Why do it if you don't have the need?

    Software engineering should be about managing complexity, not creating it.