QString::toStdString() crashes

今天在Qt中开发程序时,遇到一个QString::toStdString()的内存问题,用法如下:

void test(const QString& theFileName)
{
    std::string aFileName = theFileName.toStdString();

    std::ofstream aFile(aFileName);
    aFile << aFileName;
    
}

在函数还没执行完就崩溃了,跟踪发现是std::string的问题。最后发现是因为引用的库的Runtime Library不同导致的,一个是MDd,一个是MTd,后来改成一致即可。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
Making the absolute best of ourselves is not an easy task. It is a pleasurable pursuit...but it requires patience, persistence, and perseverance.
做最好的自己并不容易,这是很美好的愿望,需要耐心、坚持和毅力