Qt SQL

Qt 6 的变化是有意识地使框架更高效、更易用的结果。

我们尝试在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为一个更好的框架,有些改动是不可避免的。

在本主题中,我们总结了Qt SQL 中的这些变化,并提供了处理这些变化的指导。

QSqlQuery 类

boundValues() 签名

boundValues()的返回类型已从QMap<QString,QVariant> 变为QVariantList 。顺序可以依赖,因此它将与准备查询中的绑定顺序一致。更改代码如下:

QMap<QString, QVariant> values = boundValues();
int id = values[":id"].value().toInt();
QList<QVariant> values = boundValues().values();
int id = values.at(0).toInt();

改为

QList<QVariant> values = boundValues().values();
int id = values.at(0).toInt();

© 2025 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.