For just practice, using QT library I am trying to select a folder and list the name of the dicom files in that folder. The following is code for that:

```
int main(int argc, char* argv[])
{

    QApplication app(argc, argv);
    QString fileName = QFileDialog::getExistingDirectory();

    if (fileName.isEmpty())
    {
        std::cout << "Got an empty file!\n";
    }
    else
    {
        QStringList nameFilter;
        QDir dir(fileName);
        nameFilter << "*.dcm";
        QFileInfoList list = dir.entryInfoList( nameFilter, QDir::Files );
        int numberOfFiles=list.count();

        for(int i=0;i<numberOfFiles;i++)
        {
            QString filena=list[i].fileName();
            string a=filena.toStdString();
            cout<<a<<endl;

        }
    }
   return 0;
}

```

Here I have found out that the function `toStdString`, which is actually `std::string QString::toStdString () const`, gives Heap error. I know the replacement to get rid of this error is to use `toLocal8Bit().constData()`, but I'm curious what's the main reason behind the heap error provided by toStdString. Is it because it is `const` type and my for loop is trying overwrite the const variable everytime?