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::fromStdString/toStdString convertion error
Forum Updated to NodeBB v4.3 + New Features

QString::fromStdString/toStdString convertion error

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 519 Views
  • 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.
  • F Offline
    F Offline
    farafonov.alexey
    wrote on last edited by
    #1

    Greetings!
    The problem is similir to:
    Re: QString::fromStdString/toStdString wrong behavior.

    We are using Qt version 5.13.0 with prebuilt components for MinGW 7.3.0 64 bit. Also we use Protobuf 3.9.0 for serialization.
    There are some issues with the code below. The serialized string is protobuf SerializeAsString() value.

    std::string serialized = "\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\372\001"
    auto q_value = QString::fromStdString(serialized);
    auto serialized_bug = q_value.toStdString();
    // here serialized_bug = "\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\357\277\275\001"
    

    As you can see serialized != serialized_bug there is the difference in the end:

    1:"\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\372\001"
    2:"\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\357\277\275\001"
    

    Here is screenshot:
    b1abf02e-36cd-4277-a712-ea22e9b8c535-image.png

    Can someone explain what is going on. Maybe there is some explanation of this behavior.

    aha_1980A 1 Reply Last reply
    0
    • F farafonov.alexey

      Greetings!
      The problem is similir to:
      Re: QString::fromStdString/toStdString wrong behavior.

      We are using Qt version 5.13.0 with prebuilt components for MinGW 7.3.0 64 bit. Also we use Protobuf 3.9.0 for serialization.
      There are some issues with the code below. The serialized string is protobuf SerializeAsString() value.

      std::string serialized = "\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\372\001"
      auto q_value = QString::fromStdString(serialized);
      auto serialized_bug = q_value.toStdString();
      // here serialized_bug = "\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\357\277\275\001"
      

      As you can see serialized != serialized_bug there is the difference in the end:

      1:"\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\372\001"
      2:"\n&{0f735d28-2cc8-4696-87f5-e57dab1976a4}\022\003\061\061\061*\v0:COM6:COM70\001B\004COM1H\001P\357\277\275\001"
      

      Here is screenshot:
      b1abf02e-36cd-4277-a712-ea22e9b8c535-image.png

      Can someone explain what is going on. Maybe there is some explanation of this behavior.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      @farafonov-alexey

      QString is an unicode UTF-16 string and cannot store anything but (localized) text.

      In your serialized data you have non-text control characters that cannot be stored in a QString.

      Solution: use QByteArray instead.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      8
      • semlanikS Offline
        semlanikS Offline
        semlanik
        wrote on last edited by
        #3

        Probably https://github.com/semlanik/qtprotobuf will be useful for you

        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