Truncated decimal values in graphic mode only
thomaslepoix opened this issue · 0 comments
thomaslepoix commented
I open an issue as I find this bug interesting. It might help a user spotting it or another developper facing the same problem.
Qucs-RFlayout parses schematic files correctly when using its CLI. But using the Qt GUI, decimal values are truncted at the dot.
In both cases, the same parser is used so what is going on?
Here is the isolated problem :
// g++ -g 28.stoldqt.cpp -I/usr/include/x86_64-linux-gnu/qt5/ -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -fPIC -lQt5Core -lQt5Widgets -o 28
#include <QApplication>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
cout << "stold : " << stold("9.8e-2") << "\n";
QApplication app(argc, argv);
cout << "stold : " << stold("9.8e-2") << "\n";
return(0);
}
stold : 0.098
stold : 9
It is due to QApplication()
unsetting the C library locales by performing setlocale(LC_ALL, "")
.
The problem is described here and is solved this way :
// g++ -g 28.stoldqt.cpp -I/usr/include/x86_64-linux-gnu/qt5/ -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -fPIC -lQt5Core -lQt5Widgets -o 28
#include <QApplication>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
cout << "stold : " << stold("9.8e-2") << "\n";
QApplication app(argc, argv);
cout << "stold : " << stold("9.8e-2") << "\n";
setlocale(LC_NUMERIC, "C");
cout << "stold : " << stold("9.8e-2") << "\n";
return(0);
}
stold : 0.098
stold : 9
stold : 0.098