Qt equivalent of .NET data binding?

前端 未结 3 2019
北恋
北恋 2021-02-07 02:07

Is there an equivalent of .NET\'s data binding in Qt?

I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database.

3条回答
  •  萌比男神i
    2021-02-07 02:11

    One way is using Qt Model/View Classes (with base at QAbstractItemModel), but they need that you widget inherits QAbstractItemView (this is widgets like QTableView etc.).
    If you want map Qt model to set of widgets, which haven't nothing common with QAbstractItemView you can use QDataWidgetMapper, which maps separate widget to Qt Model/View indexes. But anyway, as said Aaron Digulla, you must write some boiler plate code...

提交回复
热议问题