我已经调试了2个小时了,最终问题出在这里。如果我调用QString::toStdString
QString s = "testtesttesttesttesttest";
const std::string &temp = s.toStdString();
程序后来在std::string析构函数处崩溃。
__CLR_OR_THIS_CALL ~basic_string()
{ // destroy the string
_Tidy(true); // <---- It crashes on this line.
}
一开始我以为这是内存损坏,但即使 main()
只包含这两行代码也会发生。是否有人知道为什么会发生这种情况,以及如何修复它?
我的 Qt 版本是 4.8.1
。
string temp = s.toStdString();
也会发生同样的事情,只是因为toStdString()
返回的临时变量的析构函数会立即被调用,所以它会更早地发生。我该如何查看我正在使用的 Qt 版本?我应该去哪里看?这个项目是由其他人设置的,我没有在 Visual Studio 中使用 Qt 的经验,只有在 Qt Creator 中使用的经验。 - sashoalmstd::string stdUtf8 = qs.toUtf8().constData();
- Najzero4.8.1
。这就是qVersion()
返回的内容。 - sashoalm