mercredi 21 décembre 2016

Strange error initializing a QApplication before using std::stod

i'm receiving a very very strange behavior in my current project. I use the DICOM library dcmtk to read information from some dicom files. Qt is meant to show images. During the information extraction, I have to convert fields of the format "<64bit float>\<64 bit float>" (Dicom Tag PixelSpacing). I split into 2 strings at "\" and convert the strings to a double. So far, everything works fine. Well, almost: Whenever I create a QApplication object before I convert the strings to doubles, it gives me integers instead of doubles.

The code looks like this:

// 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]);
}

It confuses me even more, that it does work stepping through the code using QtCreator and GDB. However, when i run the executable, i get integers again.

So i tracked the issue down to the stod operation: I get the right strings out of the DICOM file, but after stod the numbers after the dot are just truncated. Same behavior with stdlib's strtod Does the QApplication allocation do something strange with the std::stod function? Since everything happens while runtime, i do not understand how.

Replacing stod with QString::toDouble resolves the issue...

I'am using gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3), GNU ld (GNU Binutils for Ubuntu) 2.24

Other code dependencies include Eigen3, Boost.Python. The code is built using a CMake project with QtCreator as IDE.

Has anyone an idea where this problem comes from? Is this a Qt bug?

Aucun commentaire:

Enregistrer un commentaire