Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123993

[Reg 6.6 -> 6.7] QVariantList conversion from/to QML broken in Qt 6.7

    XMLWordPrintable

Details

    • Linux/X11, Windows
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            olivier.decanniere Olivier De Cannière
            kai_nickel Kai Nickel
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes