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

QJsonValue::fromVariant should not return Null if QVariant contains QJsonValue type

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • 5.6.0
    • 5.3.1
    • Core: I/O
    • None

    Description

      Problem is when QVariant contains value of QJsonValue, QJsonObject or QJsonArray type.
      QJsonValue::fromVariant() will then try to use conversion to String and if it fails it will return Null QJsonValue.

      Example:

      #include <QCoreApplication>
      #include <QVariant>
      #include <QJsonValue>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QJsonValue jsonValue(1);
          QVariant var(jsonValue);
      
          qDebug() << var;
          // output: QVariant(QJsonValue, QJsonValue(double, 1) )
      
          qDebug() << QJsonValue::fromVariant(var);
          // output: QJsonValue(null)
      
          return 0;
      }
      

      It would be much better if this could work in more natural way.
      Converting QVarinat containing one of QJsonValue types should result into QJsonValue of same type.

      https://qt-project.org/doc/qt-5/qjsonvalue.html#fromVariant

      Attachments

        For Gerrit Dashboard: QTBUG-41234
        # Subject Branch Project Status CR V

        Activity

          People

            laknoll Lars Knoll
            dorny Michal Dorner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes