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. After using toStdString, the string exhibited abnormal behavior.

After using toStdString, the string exhibited abnormal behavior.

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 285 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.
  • J Offline
    J Offline
    John Van
    wrote on last edited by John Van
    #1
    QString s1 = QString::fromLocal8Bit("9876543210");
    auto s5 = s1.toLocal8Bit();
    auto s6 = s5.toStdString();
    auto s7 = std::string(s5.constData(), s5.length());
    printf("%d %d ", s6.size(), s7.size());
    

    65d3dbc9-977e-49d2-b089-a5540ebdf047-image.png

    1 Reply Last reply
    0
    • J John Van

      @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #5

      @John-Van said in After using toStdString, the string exhibited abnormal behavior.:

      @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

      @Christian-Ehrlicher is suggesting you are mixing debug and release libraries. Check your compile/link commands carefully, particularly how you are compiling your code versus which libraries you are using/how they were compiled. We have often found that people are inadvertently e.g. compiling for debug but linking with release libraries or vice versa, which is not allowed and leads to unexpected behaviour.

      Also if you have a Windows problem please state what compiler you are using --- MSVC or MinGW, we cannot guess. You now have responses indicating it works correctly with each of them.

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

        Don't mix debug and release libraries. It is working as expected here with MSVC.

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

        J 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          Don't mix debug and release libraries. It is working as expected here with MSVC.

          J Offline
          J Offline
          John Van
          wrote on last edited by
          #3

          @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

          B JonBJ 2 Replies Last reply
          0
          • J John Van

            @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

            B Offline
            B Offline
            Bonnie
            wrote on last edited by
            #4

            @John-Van said in After using toStdString, the string exhibited abnormal behavior.:

            Is this a bug in version 5.15?

            I don't think so. I also have it working as expected in debug mode with my 5.15.2 MinGW.

            1 Reply Last reply
            0
            • J John Van

              @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #5

              @John-Van said in After using toStdString, the string exhibited abnormal behavior.:

              @Christian-Ehrlicher Yes, this issue only occurs in debug mode, but it uses debug libraries. Is this a bug in version 5.15?

              @Christian-Ehrlicher is suggesting you are mixing debug and release libraries. Check your compile/link commands carefully, particularly how you are compiling your code versus which libraries you are using/how they were compiled. We have often found that people are inadvertently e.g. compiling for debug but linking with release libraries or vice versa, which is not allowed and leads to unexpected behaviour.

              Also if you have a Windows problem please state what compiler you are using --- MSVC or MinGW, we cannot guess. You now have responses indicating it works correctly with each of them.

              1 Reply Last reply
              0
              • J John Van has marked this topic as solved on

              • Login

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