Making a gui binary calculator

I'm trying to make a binary calculator that can only use 0's and 1's using QT and visual studio. Only problem is that it won't take numbers that start with 0. For example it won't let me enter 000101, it will only put 101. How do I fix this so that it takes all the digits I click on in the calculator?

code for the push digit button

1
2
3
4
5
6
7
8
9
10
11
12
13
void QtProgramWin::pushDigit()
{
	QPushButton * button = (QPushButton*)sender();

	int labelNumber;
	QString newLabel;

	labelNumber = (ui->label->text() + button->text()).toInt();
	
	newLabel = QString::number(labelNumber, 'g', 16);

	ui->label->setText(newLabel);
}
closed account (48T7M4Gy)
You might be better off staying with strings and/or chars because leading zeroes for an int are ignored unless you want to get into masking (surf around Qt if you like ) etc which seems over-complicated for this job.

With Qt or GUI's in general it's not a bad idea to have a general string processor function completely separate from Qt-speak which processes the string and returns the result to the relevant box in the GUI.

That's the way its meant to work with the GUI acting as a view of the processing that goes on rather than being the processor itself.

That means the first step is to write a function along these lines
string binary_add(string1,string2)()

So, in the GUI when the add button is pressed the Qt function associated with that sends the 2 strings in the test boxes to the function and displays the answer in the answer box on the GUI.
Gotchu, figured the only way was to keep it as a string. Thanks for the help.
Registered users can post here. Sign in or register to post.