QString :: toStdString()崩溃对std :: string析构函数 [英] QString::toStdString() crashes on std::string destructor

查看:4311
本文介绍了QString :: toStdString()崩溃对std :: string析构函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经调试这个2个小时了,它归结为这个。如果我调用 QString :: toStdString

I've been debugging this for 2 hours now, and it boils down to this. If I call QString::toStdString

QString s = "testtesttesttesttesttest";
const std::string &temp = s.toStdString();

程序后来崩溃std :: string析构函数

the program later crashes on std::string destructor

__CLR_OR_THIS_CALL ~basic_string()
    {   // destroy the string
    _Tidy(true); // <---- It crashes on this line.
    }

我认为这是内存损坏, c $ c> main()只包含这两行。

I thought it was memory corruption at first, but this happens even if main() contains only those 2 lines. Does anyone know why this happens, and also how can I fix it?

我的Qt版本是 4.8.1 没有人知道为什么会发生这种情况, 。

My Qt version is 4.8.1.

推荐答案

您的Qt DLL需要使用STL支持和与您的代码完全相同的C-Runtime库进行编译。它看起来好像你在同一时间使用两个不同的CRT,这将破坏在一个堆上由Qt创建的对象到您的程序使用的堆中。

Your Qt DLLs need to be compiled with STL support and exactly the same C-Runtime Library as your code. It looks as though you are using two different CRTs at the same time, which would destroy the objects created on one heap by Qt into the heap used by your program.

检查与Dependency Walker的DLL使用!

Check the DLL Usage with the Dependency Walker!

这篇关于QString :: toStdString()崩溃对std :: string析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆