我有一个Qt应用程序,我正在用更新版本的VC++和GDCM构建它。我以前用VC++ 2015和老版本的GDCM构建了这个应用程序,它编译并运行得很好。现在,我在字符串赋值中遇到了一个异常。
gdcm::Reader r;
r.SetFileName(f.toStdString().c_str());
if (r.Read()) {
gdcm::StringFilter sf;
sf = gdcm::StringFilter();
sf.SetFile(r.GetFile());
std::string s;
/* get modality */
gdcm::Tag tag = gdcm::Tag(0x0008,0x0060);
s = sf.ToString(tag); // <-- runtime error here...
fileModality = QString(s.c_str());
/* get patientID */
s = sf.ToString(gdcm::Tag(0x0010,0x0020));
filePatientID = QString(s.c_str());
/* get protocol (seriesDesc) */
s = sf.ToString(gdcm::Tag(0x0008,0x103E));
fileProtocol = QString(s.c_str());
}如果我使用assign函数,错误将移到下一行,即从字符串到c_str的转换。
s.assign(sf.ToString(tag));
fileModality = QString(s.data());我不知道发生了什么,但是GDCM没有正确返回string对象似乎是个问题。
编辑:错误是具有以下内容的对话框
The inferior stopped because it triggered an exception.
Stopped in thread 0 by: Exception at 0x7ffaa7b8f621, code: 0xc0000005: read access violation at: 0xfffffffffff, flags=0x0 (first chance).和调用堆栈,从我自己的函数调用开始
1 std::_Container_base12::_Swap_all xutility 239 0x7ff7764a7b7a
2 std::_String_alloc<std::_String_base_types<char,std::allocator<char>>>::_Swap_all xstring 2029 0x7ff7764a7af7
3 std::string::_Assign_rv_contents_with_alloc_always_equal xstring 2353 0x7ff7764a619d
4 std::string::_Assign_rv_contents xstring 2326 0x7ff7764a6132
5 std::string::operator= xstring 2308 0x7ff7764a37cd
6 MainWindow::GetFileType mainwindow.cpp 477 0x7ff77648784c
... <More> 发布于 2019-02-28 19:08:31
我把这个放在这里以防有人遇到类似的问题。
我解决了这个问题。GDCM是在发行版中编译的。但是我的应用程序是用Debug编译的。不知怎么的,它链接得很好,并且大部分都在运行,但是当它遇到来自GDCM库的函数调用时,它就崩溃了。编译发行版中的所有内容或调试修复它。
https://stackoverflow.com/questions/54927974
复制相似问题