Qt相当于.NET数据绑定? [英] Qt equivalent of .NET data binding?

查看:204
本文介绍了Qt相当于.NET数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用QStrings填充一些组合框和其他小部件,这些小部件引用了数据库中的特定实体。然而,如果我可以将数据绑定到这些字符串,而不是再次基于新的组合框选择或基于构建我自己的使用QStrings搜索的实体索引的其他方案来再次查询数据库,那将会更加清晰。



我想出的最好的办法是从QString派生这些实体,并将它们推送到这些小部件中,但我还没有实际尝试。我不知道是否会按照我想要的方式工作,这似乎是一个讨厌的黑客。



如果没有数据绑定,你建议什么



谢谢。

解决方案

你可以设置一个模型。对于QObject一般来说,您可以使用通知信号连接属性或其他非属性相关的信号。我想还有另一种办法,但我不记得了。


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. However, it would be cleaner if I could bind the data to these strings rather than either querying the database again based off of a new combobox selection or some other scheme based off of building my own index of entities that would be searched with the QStrings.

The best I've come up with is to derive these entities from QString and pushing them into the widgets this way, but I've yet to actually try it. I'm not sure if it will work the way I want it to, and it seems like a nasty hack.

If there is no data binding, what do you suggest?

Thank you.

解决方案

Well, for combobox specifically, you can set a model. For QObjects in general you can use the notify signal for properties to connect or other non-property related signals. I think there is another way to do it but I can't recall.

这篇关于Qt相当于.NET数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆