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::toStdString memory leak

QString::toStdString memory leak

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k 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.
  • M Offline
    M Offline
    mshehata
    wrote on last edited by
    #1

    Hi All, I am using the member function "toStdString" of QString class to convert QString to std string. Conversion is done correctly but I ran memcheck tool of valgrind to check the memory and I found that there are a lot of leaks existing due to the conversion using "toStdString".
    Is it a known issue? and if yes, Is there a way to avoid using it and perform the same conversion?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet

      I just checked this on Windows with "VLD":https://vld.codeplex.com/ and can't confirm this.
      Can you show an example of code that seems to leak?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tarod.net
        wrote on last edited by
        #3

        I've just coded this lines and valgrind didn't find any memory leak.

        @
        #include <QString>
        #include <iostream>

        int main(int argc, char *argv[])
        {
        QString qstring("test");

            std::cout << qstring.toStdString() << std::endl;
        
            return 0;
        

        }
        @

        "Individually, we are one drop. Together, we are an ocean."

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mshehata
          wrote on last edited by
          #4

          Ok, many thanks Chris and tarod.net for your efforts.
          It seems to be a false detection.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tarod.net
            wrote on last edited by
            #5

            Great! :)

            "Individually, we are one drop. Together, we are an ocean."

            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