Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.7.0
-
None
-
-
152e6716b (dev), f1e3b4f2a (6.7)
Description
A QVariantList returned from Cpp to QML could be used just like a regular QML Javascript array, for example:
- you could use it to call a Cpp function taking a QJsonArray argument
- you could put it in a Javascript object and call a Cpp function taking a QJsonObject argument
Both does not work anymore with Qt 6.7.0, see the following example.
cpp
QVariantList MiscUtils::createVariantList() const { return {QString("cpp"), QString("variant"), QString("list")}; } void MiscUtils::logArray(const QJsonArray& arr) const { const auto str = QJsonDocument(arr).toJson(QJsonDocument::Compact); std::cout << "Cpp QJsonArray: " << str.toStdString() << "\n"; } void MiscUtils::logObject(const QJsonObject& obj) const { const auto str = QJsonDocument(obj).toJson(QJsonDocument::Compact); std::cout << "Cpp QJsonObject: " << str.toStdString() << "\n"; }
qml
const varlist = MiscUtils.createVariantList(); console.log("QML varlist:", JSON.stringify(varlist)); const obj = { test: varlist }; console.log("QML object:", JSON.stringify(obj)); MiscUtils.logArray(varlist); MiscUtils.logObject(obj);
Output Qt 6.6
QML varlist: ["cpp","variant","list"] QML object: {"test":["cpp","variant","list"]} Cpp QJsonArray: ["cpp","variant","list"] Cpp QJsonObject: {"test":["cpp","variant","list"]}
Output Qt 6.7.0
QML varlist: ["cpp","variant","list"] QML object: {"test":["cpp","variant","list"]} Cpp QJsonArray: [] Cpp QJsonObject: {"test":{"0":"cpp","1":"variant","2":"list"}}
Attachments
For Gerrit Dashboard: QTBUG-123993 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
553607,16 | V4: Handle all array-like containers when converting to QJsonArray | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
556695,3 | V4: Handle all array-like containers when converting to QJsonArray | 6.7 | qt/qtdeclarative | Status: MERGED | +2 | 0 |