Speaking about WPF Binding compared to Qt, did anybody tried to achieve the functionality that in WPF achived by the following:
<ComboBox ItemsSource="{Binding Items}" SelectedValue="{Binding SelectedItem}" />
Here are:
- Items collection (member of the Model) bound as a source of combo drop down.
- Then combo selection bound to SelectedItem (member of the Model).
In Qt:
- Could relatively easy achieved by QComboBox.setModel().
- Is a bit harder because it's two-way binding. View-to-model changes could be done with signals (QComboBox.activatedIndexChanged). Model-to-view changes could be also done through signals (to follow Model-View separation you'll need to add signal to your model, emit it whenever SelectedItemIndex is changed on the model, and on Widget side connect to that signal for calling QComboBox.setCurrentIndex()).
All these seemed to be very general things and could be done in separate library of binding helpers. For example, I have right now in my QtJambi code something like this:
ComboBoxBind bind = new ComboBoxBind(comboBox);
bind.selectedIndex(model, "SelectedItemIndex").items(model.getItems());
The currentIndex of QComboBox here is bound to SelectedItemIndex member of the model (with corresponding get/set methods). So I can call setSelectedItemIndex on model or change selection in UI - model will be insync with view.
The question is: Does anybody know if the Binding library already exists? Has anybody tried to create something similar?
Sorry, it could be that I'm missing something. I'm pretty experienced in WPF but just started with Qt and developing UI with QtJambi right now. Any comments/ideas are welcome!
This question is related to this one: Qt equivalent of .NET data binding?, but I think question there wasn't answered at all. At least it doesn't provide any sample of WPF-similiar Binding in Qt.