Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136459

QString::toStdString() returns NULL on Windows x64

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.9.0
    • None
    • Visual Studio 17.13.6 (latest as of this report), building in C++23 mode
    • Windows

    Description

      This function returns NULL on Windows. It works as expected on Mac and GNU/Linux.

       std::string
      get_for_filename ()
      {
        QDateTime datetime = QDateTime::currentDateTime ();
        QString   str_datetime =
          datetime.toString (QString::fromUtf8 ("yyyy-MM-dd_HH-mm-ss"));
      
        return str_datetime.toStdString ();
      }
      

      I stepped through the debugger in visual studio and I can see the correct string value inside my `str_datetime` variable. The result of this function is NULL according to the debugger, and I also get a memory-related fatal error when I attempt to use that result.

      If I change the last line to `return str_datetime.toUtf8 ().data ();` then this function returns the expected string and everything works.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            alextee Alexandros Theodotou
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes