ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hello!
I decided to try and learn some C++ programming with GTKmm the other day, i have programmed a little C++ a couple of years back but nothing fancy.
I have been able to draw some inputs and buttons on the window but that's about as far as i can get at this point.
As you can see i'm trying to make a basic calculator that just adds two numbers together and displays the result.
The question here is how do i access the values from numberone and numbertwo entries and put the sum of these in the label answerlabel. I tried passing some arguments to the function calculate() but that didn't work.
Any tips on good ways to do this would be appreciated.
have you found out how to proceed yet? If not please find here one possible solution in C++ with classes and everything. I think it is best to look at the examples bundled with Gtkmm to learn how to make a structured program. I split up the code on three files and updated the makefile accordingly. Have fun!
Hi!
Sorry for a late reply, haven't had time to look at this latley.
Thanks a lot for your replys, it helps a lot starting to understand better how to structure programs now.
Your example was great m95vebj, however i had a question:
This row is a bit confusing for me: Simple_Calculator::Simple_Calculator() : calcbutton("Calculate"), pluslabel("+"), answerlabel("=")
what exactly needs to be added to this row? As far as i can see it contains all widgets except numone and numtwo?
If i wanted to add more labels and stuff, do these go on this row as well?
Hi!
Sorry for a late reply, haven't had time to look at this latley.
Thanks a lot for your replys, it helps a lot starting to understand better how to structure programs now.
Your example was great m95vebj, however i had a question:
This row is a bit confusing for me: Simple_Calculator::Simple_Calculator() : calcbutton("Calculate"), pluslabel("+"), answerlabel("=")
what exactly needs to be added to this row? As far as i can see it contains all widgets except numone and numtwo?
If i wanted to add more labels and stuff, do these go on this row as well?
Thanks.
// magoot
Hi again,
Those lines initiates the widgets and puts the initial text on them. I suppose you could have used e.g. answerlabel.add_text("="); later on in stead. You do however need to declare new widgets in the class declaration to be useful.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.