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

QCborArray::toCborValue().toCbor() doesn't work properly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.12
    • Core: Other
    • None
    • All

    Description

      The following code shows the problems:

      #include <QBuffer>
      #include <QCborArray>
      #include <QCborMap>
      #include <QCborStreamReader>
      #include <QCborStreamWriter>
      #include <QCborValue>
      
      int main(int argc, char *argv[])
      {
          QVariantList args = {1, 2, 3, "bla"};
          QBuffer buff;
          buff.open(QIODevice::ReadWrite);
          QCborStreamWriter writer(&buff);
          writer.startMap();
              writer.append(quint8(1));
              writer.append(1);
      
              writer.append(quint8(2));
              //writer.startArray(); // doesn't help
              auto array = QCborArray::fromVariantList(args);
              writer.append(array.toCborValue().toCbor());
              //writer.endArray();
      
      //      This one works a little bit, but it changes the type of the qvariants (from int to qbytearray)
      //        writer.startArray(args.size());
      //        for (const auto &arg : args)
      //            writer.append(QCborValue::fromVariant(arg).toCbor());
      //        writer.endArray();
          writer.endMap();
      
          buff.seek(0);
          QCborStreamReader reader(&buff);
          while (reader.hasNext() && !reader.isMap() && reader.lastError() == QCborError::NoError)
              reader.next();
          Q_ASSERT(reader.isMap());
          QCborValue invokePacketValues = QCborValue::fromCbor(reader);
          Q_ASSERT(reader.lastError() == QCborError::NoError);
          Q_ASSERT(invokePacketValues.isMap());
          int val1 = invokePacketValues[quint8(1)].toInteger();
          QVariantList argsRead = invokePacketValues[2].toArray().toVariantList();
          qDebug() << val1 << args << argsRead;
      }
      

      The problems:

      1. writer.append(QCborArray::fromVariantList(args).toCborValue().toCbor()) - I'm expecting to create an array.
      2. QCborValue::toArray().toVariantList() changes the types of QVariants

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            taipan BogDan Vatra
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes