Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Nested map in QCborStreamWriter ?
Forum Updated to NodeBB v4.3 + New Features

Nested map in QCborStreamWriter ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 829 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atrSbt
    wrote on last edited by
    #1

    So far, I managed to write large nested maps of strings, floats and ints using nested QJsonMap's in a QJsonDocument, but only after all the data is generated, the writing process is slow and the outfile is huge (>400MB).
    So I turned my attention to CBOR and its stream writer, but it seems that QCborStreamWriter does not handle nested maps (QCborStreamWriter::append() does not take a QCborMap as argument).
    Is there a way to do it anyway or an alternative to QCborStreamWriter that handles nested maps ?
    Thanks

    1 Reply Last reply
    0
    • A atrSbt

      @JKSH I submitted the feature request here, I hope I did it correctly.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #8

      @atrSbt said in Nested map in QCborStreamWriter ?:

      @JKSH I submitted the feature request here, I hope I did it correctly.

      Yep, you did it correctly.

      And it looks like the Qt Core maintainer has provided a simpler solution:

      QCborStreamWriter stream = ...
      QCborMap map = ...
      
      map.toCborValue().toCbor(stream);
      
      // OR:
      QCborValue(map).toCbor(stream);
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        QCBorMap has a toCBorValue() function.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          QCBorMap has a toCBorValue() function.

          A Offline
          A Offline
          atrSbt
          wrote on last edited by atrSbt
          #3

          Thank you for your reply @Christian-Ehrlicher
          I see, however this probably won't work since append() does not take a QCborValue as an argument either. I suppose I could then convert the QCborValue further to a QByteArray, but I'm not sure if it's the best way to do this...

          QCborStreamWriter writer;
          writer.startArray();
          QCBorMap map;
          writer.append(map.toCBorValue().toByteArray());
          writer.endArray();
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Ok I see.

            Then a nested call to https://doc.qt.io/qt-6/qcborstreamwriter.html#startMap-1 / end map should work. Strange that there are no convenience functions for this.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            2
            • Christian EhrlicherC Christian Ehrlicher

              Ok I see.

              Then a nested call to https://doc.qt.io/qt-6/qcborstreamwriter.html#startMap-1 / end map should work. Strange that there are no convenience functions for this.

              A Offline
              A Offline
              atrSbt
              wrote on last edited by
              #5

              Indeed this works:

              QCborStreamWriter writer;
              writer.startMap();
              writer.append("A");
              writer.append(1);
              writer.append("B");
              writer.append(2);
              writer.append("C");
              writer.startMap(); // start nested map
              writer.append("C1");
              writer.append(3.1);
              writer.append("C2");
              writer.append(3.2);
              writer.append("C3");
              writer.append(3.3);
              writer.endMap(); // end nested map
              writer.endMap();
              

              and produces the following tree:

              {
              "A": 1,
              "B": 2,
              "C": {
                "C1": 3.1,
                "C2": 3.2,
                "C3": 3.3
              },
              "D": 4
              }
              

              But I agree, a convenience function would really help, especially with many nested levels and elements.
              Thanks for your help !

              JKSHJ 1 Reply Last reply
              2
              • A atrSbt

                Indeed this works:

                QCborStreamWriter writer;
                writer.startMap();
                writer.append("A");
                writer.append(1);
                writer.append("B");
                writer.append(2);
                writer.append("C");
                writer.startMap(); // start nested map
                writer.append("C1");
                writer.append(3.1);
                writer.append("C2");
                writer.append(3.2);
                writer.append("C3");
                writer.append(3.3);
                writer.endMap(); // end nested map
                writer.endMap();
                

                and produces the following tree:

                {
                "A": 1,
                "B": 2,
                "C": {
                  "C1": 3.1,
                  "C2": 3.2,
                  "C3": 3.3
                },
                "D": 4
                }
                

                But I agree, a convenience function would really help, especially with many nested levels and elements.
                Thanks for your help !

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #6

                @atrSbt said in Nested map in QCborStreamWriter ?:

                Indeed this works:

                Great!

                a convenience function would really help, especially with many nested levels and elements.

                Would you be willing to submit a feature request to https://bugreports.qt.io/ ?

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                A 1 Reply Last reply
                0
                • JKSHJ JKSH

                  @atrSbt said in Nested map in QCborStreamWriter ?:

                  Indeed this works:

                  Great!

                  a convenience function would really help, especially with many nested levels and elements.

                  Would you be willing to submit a feature request to https://bugreports.qt.io/ ?

                  A Offline
                  A Offline
                  atrSbt
                  wrote on last edited by
                  #7

                  @JKSH I submitted the feature request here, I hope I did it correctly.

                  JKSHJ 1 Reply Last reply
                  1
                  • A atrSbt

                    @JKSH I submitted the feature request here, I hope I did it correctly.

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #8

                    @atrSbt said in Nested map in QCborStreamWriter ?:

                    @JKSH I submitted the feature request here, I hope I did it correctly.

                    Yep, you did it correctly.

                    And it looks like the Qt Core maintainer has provided a simpler solution:

                    QCborStreamWriter stream = ...
                    QCborMap map = ...
                    
                    map.toCborValue().toCbor(stream);
                    
                    // OR:
                    QCborValue(map).toCbor(stream);
                    

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      atrSbt
                      wrote on last edited by
                      #9

                      Indeed. Is there a way one could set your post as the solution instead of Christian's ?

                      SGaistS 1 Reply Last reply
                      0
                      • A atrSbt

                        Indeed. Is there a way one could set your post as the solution instead of Christian's ?

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        Hi,

                        @atrSbt mark the thread as unsolved and then the newly elected answer as the correct one.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved