qt basic_string上的C ++异常析构函数仅在双击运行时 [英] qt C++ exception on basic_string destructor on double click run only

查看:547
本文介绍了qt basic_string上的C ++异常析构函数仅在双击运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  CAtlString str = currentFolder-> whatsThis()。toStdWString()。c_str ; 

currentFolder是qt QTreeWidgetItem *。
当我运行程序从VS2010它工作确定。但是当我通过双击在同一个文件夹(x64 / Debug或Release)启动程序,我有例外:

 未处理的异常在0x00007ffe2a07572a(ntdll.dll)在test.exe:0xC0000005:访问冲突读取位置0xffffffffffffffff。 

在basic_string析构函数中的dealloc上:

 〜basic_string()// xstring 
{//销毁字符串
_Tidy(true);
}

// ...


$ b b

  void deallocate(pointer _Ptr,size_type)// in xmemory 
{// deallocate object at _Ptr,ignore size
:: operator delete(_Ptr) ;
}



我试图直接删除字符串,清除,我有同样的结果。我也试图使用不同的运行时和部署包,没有幸运。 (用Dependency Walker搜索)。
为什么程序在VS2010下工作?
thx!



更新这是最小的代码重现了问题:


I have following code:

CAtlString str = currentFolder->whatsThis().toStdWString().c_str();

currentFolder is qt QTreeWidgetItem*. When I run program from VS2010 it works ok. But when I start program by double click in the same folder (x64/Debug or Release), I have exceptions:

Unhandled exception at 0x00007ffe2a07572a (ntdll.dll) in test.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.

on dealloc in basic_string destructor:

~basic_string()      // xstring
    {   // destroy the string
    _Tidy(true);
    }

// ...

void deallocate(pointer _Ptr, size_type) // in xmemory
    {   // deallocate object at _Ptr, ignore size
    ::operator delete(_Ptr);
    }

I`m trying to delete string directly, clean, erase - but every time I had the same result. Also I had tried to use different runtimes and deploy packages, without lucky. (searched with Dependency Walker). Why program works under VS2010? And how can I fix standalone running? thx!

Update This is the minimal code reproduced the problem: zalil.ru use x64 config and run program by double click for catch the exception.

Update2 if I keep wstring pointer alive (using temp variable), I have following error:

解决方案

I have found problem solution. As I can understood, on my computer I have mixed installed Qt libraries (3 different versions) and when std::string destructor called, I have UB because wrong runtime called. To solve my problem, I need to avoid using toStdWString/c_str in QString conversions //for example like this auto arr = currentFolder->whatsThis().toUtf8(); std::string temp_str(arr.data()); qDebug() << temp_str.c_str();

or recompile/clean reinstall all libraries that I have used. Its so strange configuration error) There is the page with decision: forum.qt.io

这篇关于qt basic_string上的C ++异常析构函数仅在双击运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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