Hacker News new | ask | show | jobs
by hermitcrab 1957 days ago
I find that Qt signals and slots works pretty well for managing complexity in GUIs. In this case you would connect a signal that is emitted when inventory table changes state to a slot that changes the appearance in the user avatar. This would probably be done in the pane/dialog that contains them both. They 2 components would remain nicely decoupled.

This approach isn't without it's own challenges of course. For example it is sometimes hard to keep track of what is going on in complex applications with cascades of signals and slots. Some people also hate the fact that signals and slots use auto generated code, but I have never really found that to be a problem in practise.

2 comments

If one user interaction triggers a "on user interaction" signal, which causes "value changed" signals to fire, is it possible that a widget which depends on multiple of these to get redrawn multiple times?

I'm optimistic about Qt 6's QProperty (I don't know how it compares to FRP or, as someone else mentioned, MobX), but Qt 6 currently does not have KDE libraries, or Linux themes to fit into desktop environments or distros.

Yes, potentially, if that is how you program it. But typically you call QWidget::update() which repaints the widget next time through the event loop, if anything changes. Calling QWidget::update() several times will usually only call one repaint.

One thing you have to watch out for it that programmatic changes can fire signals. If you don't want this you have to add QObject::blockSignals(true);...QObject::blockSignals(false); around your call.

I agree, but isn't that just a message bus (mentioned in the article)?
It is, he's just pointing out that the Qt developers figured this out a long time ago. Web developers like to think they're pioneers when it comes to this stuff.
I never really thought of it in those terms. But I guess signals and slots are just way to publish/subscribe to a message bus. It is quite a nice abstraction of it IMHO (which is perhaps why it didn't occur to me!).