创建数据关联表单

利用上述 SQL 模型,可以将数据库中的内容呈现给其他模型/视图组件。 对于某些应用程序,使用标准项目视图(如QTableView )来呈现这些数据就足够了。然而,基于记录的应用程序的用户通常需要基于表单的用户界面,其中数据库表中特定行或列的数据被用于填充表单上的编辑器控件。

此类数据感知表单可通过QDataWidgetMapper 类创建,这是一个通用的模型/视图组件,用于将模型中的数据映射到用户界面中的特定控件。

QDataWidgetMapper 该类针对特定的数据库表进行操作,以行或列为单位映射表中的项目。因此,将 `QDataWidgetMapper ` 与 SQL 模型结合使用,其操作方式与使用任何其他表模型一样简单。

该表展示了不同字段之间的关系

“Books”示例展示了如何通过使用QDataWidgetMapper 和一组简单的输入控件,以便于访问的方式呈现信息。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.