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. QString, toLatin1(), data(), concatenated

QString, toLatin1(), data(), concatenated

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 735 Views 1 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I have a QJsonDocument:

        QJsonDocument doc(arySetting);
    

    This is converted to Json then to a QByteArray:

        QByteArray baJSON = doc.toJson();
    

    At this point baJSON consists of 831 bytes.

    Then I strip out the whitespace and convert to a QString:

        QString strJSON = strStrip(baJSON);
    

    strJSON is 403 bytes long.

    I then convert this back to a byte array:

        baJSON = strJSON.toLatin1();
    

    Again, baJSON is 403 bytes long. I then convert this to a const char*:

        const char* cpszJSON = baJSON.data();
    

    Now looking in the debugger cpszJSON contains only 100 bytes.

    Whats going on ?

    Kind Regards,
    Sy

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

      @SPlatten said in QString, toLatin1(), data(), concatenated:

      Whats going on ?

      You're simply looking at the output of gdb which does not output all chars of a char* array (since it can get very long) but only the first 100. So you're testing wrong. Use strlen.

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

      1 Reply Last reply
      4
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        It does appear the at the same point the application is stuck.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @SPlatten said in QString, toLatin1(), data(), concatenated:

          the application is stuck.

          But this for sure does not happen due to the fat the debugger only shows the first 100 bytes of a char* pointer...

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

          1 Reply Last reply
          0
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            It could indicate memory corruption in which case it would.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              As I already told you it's the debugger which is showing only the first 100bytes and if you don't trust me use strlen() and/or print the string to e.g. stdout.

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

              1 Reply Last reply
              2

              • Login

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