Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncated decimal values in graphic mode only #4

Closed
thomaslepoix opened this issue Apr 16, 2020 · 0 comments
Closed

Truncated decimal values in graphic mode only #4

thomaslepoix opened this issue Apr 16, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@thomaslepoix
Copy link
Owner

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
@thomaslepoix thomaslepoix added the bug Something isn't working label Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant