As many long running projects, Qt too over the years has accumulated some APIs that in hindsight are deemed unsafe or sub-optimal. For example, Qt by default implicitly converts const char* to QString. While that usually only incurs a runtime overhead, maybe encoding problems, but also admittedly less cluttered code, there’s other APIs that can backfire in more subtle ways. One such API is doing a “context-less connect”. Signals and Slots are a core principle of Qt that make it super easy to connect one object to another and keep a certain separation of concerns. The typical syntax to establish an connection is: connect(sender, &Foo::somethingHappened, receiver, &Bar::doStuff); This connects the signal somethingHappened in our sender of Type Foo to the member function doStuff in our receiver (context object) of type Bar. Whenever sender “emits” somethingHappened, doStuff on receiver will be called. The neat part about Qt connections is that when receiver gets destroyed, the connection…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.