[LAD] GUI mechanics question: interaction between UI control and data

Tim Orford tim at orford.org
Sun May 29 18:05:01 CEST 2022

On Tue, May 24, 2022 at 11:40:49PM +0200, Jeanette C. wrote:
> [...]
> Consider this: An application with a toggle button (on/off), some load from
> file button and a class holding one bvoolean value connect to the on/off
> button. The class could look like this:
> class Data
> {
>   public:
>     Data(bool value): its_value(value) {}
> 	 ~Data() {}
> 	 void set(bool value) { its_value = value; }
> 	 bool get() const { return its_value; }
>   private:
>     bool its_value;
> };
> The button is connected to a Data object, via a signal, so its set(bool)
> function is called.
> The load function will load a value from a file.
> How would you normally reflect that on GUI? What's the method to not
> only set the Data object value, but also the corresponding button state?
> What's the current practise to make this two-way connection? Combine
> both button and object in a wrapper? Have some other kind of signal?
> Simple change button state in every place the Data object is changed?
> As stated above: even an old resource or documentation for a limited UI
> library will do, as long as the method shines through with little
> overhead and without anything like QML or a UI builder.


For Gtk, perhaps this answer to a similar question might be helpful:

The recommendation is to use GObject.bind_property().
This can provide one or two way binding between data and UI objects
as long as they both inherit from GObject.

Tim Orford

More information about the Linux-audio-dev mailing list