我在当前项目中收到意外行为。
我使用 DICOM 库dcmtk
从一些 dicom 文件中读取信息,并Qt
显示图像。
在信息提取过程中,我必须转换格式为“<64bit float>\<64 bit float>”(Dicom Tag PixelSpacing)的字段。我在“\”处拆分为 2 个字符串,并将字符串转换为双精度。到目前为止,一切正常。
好吧,几乎:每当我在将字符串转换为双精度数之前QApplication
创建一个对象时,它都会给我整数而不是双精度数。
代码如下所示:
// Faulty situation
Database db;
QApplication app(&argc, argv);
db.fill_from_source(source); // here i get ints instead of doubles
// Rearrange code and recompile:
Database db;
db.fill_from_source(source); // now it gets me doubles.
QApplication app(&argc, argv);
// The fill function looks like this (simplified)
void Database::fill_from_source(const Source& source){
string s = source.get_pixel_spacing_string();
vector<string> s2 = split(s, "\\");
// get the double, that should not be integers!
double a = stod(s2[0]);
double b = stod(s2[1]);
}
更让我困惑的是,它确实可以使用 QtCreator 和 GDB 逐步执行代码。但是,当我运行可执行文件时,我再次得到整数。
所以我将问题追溯到stod
操作:我从 DICOM 文件中得到了正确的字符串,但是在stod
点之后的数字被截断之后。与stdlib
's相同的行为strtod
QApplication
分配对std::stod
函数有影响吗?由于一切都发生在运行时,我不明白如何。
替换stod
为QString::toDouble
解决问题...
我正在使用gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3), GNU ld (GNU Binutils for Ubuntu) 2.24
.
其他代码依赖项包括Eigen3
, Boost.Python
. 代码是使用 CMake 项目和 QtCreator 作为 IDE 构建的。
有谁知道这个问题来自哪里?这是一个Qt错误吗?