<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>Am 08.08.2014 um 14:29 schrieb Bo Thorsen <<a href="mailto:bo@vikingsoft.eu">bo@vikingsoft.eu</a>>:<br><br></div><blockquote type="cite"><div><blockquote type="cite"><font color="#0023a3">...</font>as soon as slots of multiple<br></blockquote><blockquote type="cite"><span>classes are to be connected to a given signal "in a well-defined</span><br></blockquote><blockquote type="cite"><span>order" such a design would probably be doomed to fail rather sooner</span><br></blockquote><blockquote type="cite"><span>than later, IMHO.</span><br></blockquote><span></span><br><span>As long as your application is single threaded, then the order is </span><br><span>perfectly well defined. If you think of connections as implementations </span><br><span>of the visitor pattern with one visitor object in a list of signals, </span><br><span>then it's not hard to do this. Emitting a signal and the connected slot </span><br><span>calls are exactly the same as calling any C++ function, so the order is </span><br><span>easy.</span><br></div></blockquote><br><div>Well, I do agree there are certainly useful applications with a "well-defined order" of slot calls.</div><div><br></div><div>E.g.</div><div><br></div><div>// some c'tor</div><div>Foo::Foo() {</div><div>  connect(this, SIGNAL(whatever()), this, SLOT(mustBeCalledFirst()));</div><div>  <span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">connect(this, SIGNAL(whatever()), this, SLOT(mustBeCalledSecond()));</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">  </span><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">connect(this, SIGNAL(whatever()), this, SLOT(mustBeCalledThird()));</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">  ...</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">}</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">is certainly easy to maintain (so far!), as all connects happen "locally"; and even better if the slots are private (*), so no other class would be tempted to connect the same signal (for whatever funny reason) to those slots - possibly messing up the order.</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">But I really meant the case where you would pass along a given class instance "across other class instances" (in order to "initialise" it or whatever), and those other class instances would connect (and possibly even disconnect) signals and slots, and you'd still expect this to happen "in an ordered manner", then it takes only so long until Joe Programmer will "refactor" your code, switch two lines of code where you instantiate those "other classes" (which then connect the slots in a different order!) and bang! There you go, absolute chaos! Even in a single-threaded application.</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">Okay, I agree again that I had a hard time contrieving an example where you'd "realistically" would manage to "mess up the order in which you connect signal/slots of a given instance".</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">But given my experience with signals (keyword: "endless signal/slot loop", "signal which calls a slot which emits a signal which calls several slots which... hey! Why does this method call take so long?!") it's hard enough to deal with them properly. ;)</span></div><div><br></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">But I love the Qt signal/slot mechanism  :) </span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">(E.g. the Cocoa framework has like half a dozen different patterns to implement the "model/observer" pattern: "Key-Value Observer", events, delegates...)</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">Cheers,</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">  Oliver</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">(*) Yep, there is actually no such thing as "private slots": one can still connect any signal to a "private slot" from "outside" the class and the slot /will/ be called.</span></div></body></html>