Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Swtiching from Java to C++... need help

Name: Anonymous 2006-12-18 12:18

Ok... I've taken two semesters of Java courses at Uni, and was thinking for marketability purposes, I better learn another, probably better, language. So I decided to try learning C++ since I heard they are pretty closely related, and I decided to use gtkmm for my GUI needs. However, I am running into difficulties, and I do not know if it is because I am a gigantic faggot, or what, I can't get this to work.

My idea was to try to write a very simple program that would basically allow me to add two numbers typed into two different text boxes, and output the answer. In my naiveté, I believe that once I overcome programming something that basic, that programming something more sophisticated should only then require that I can imagine it.

The problem is, the button that I try to add to the window does not appear to show up. I am wondering if I need to instantiate a container first, or what...

Below is a copy of my super simple source. Please ignore the inefficacy of including a whole one megabyte library for now, and help explain what I am doing wrong if you are able.

Thank you.

...
#include <gtkmm.h>

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv); //This creates the GTK main.

    Gtk::Window window; //This creates a window.
   
    Gtk::Button mButton;
    mButton.set_label("_Add"); //This creates a Button and labels it "Add" with an underline for A.

    window.add(mButton); //puts m_button into window.

    Gtk::Main::run(window); //This runs the window in the GTK main.
   
    return 0;
}
...

A picture of the resultant window:

http://img508.imageshack.us/img508/175/screenshotaddinged6.png

Name: Anonymous 2006-12-18 12:30

>>1
I would consider invoking the ``show'' function on a number of objects.

Name: Anonymous 2006-12-18 12:31

Try mButton.show()

Name: Anonymous 2006-12-18 12:48

Thank you guys ever so much! The button does show up now... one more minor thing though, From the API and DOCs I'm reading, I understood it to mean that whatever character in a label for a button that is preceded by an underscore, should be underlined. This is not terribly important mind you, but the button literally had the label "_Add" as in the A was not underlined. In any case, thank you so much for the help. It feels weird knowing 40 percent of this stuff, and the other 60 makes no sense at all. :3

Name: Anonymous 2006-12-18 13:32

>>4

You're most welcome. Btw, mButton.set_use_underline(true) should help with your underline problem.

Name: Anonymous 2006-12-18 19:19

Truly, this has solved my button problem... I have played with this for some while, and have stumbled upon some new problems. I would like to use Gtk::Entry.get_text() in a function that is waiting for a signal from a button, but I am unfamiliar with how I could go about doing this in C++.

I could post the whole source if it would be helpful but I am pretty sure the most important points are:
*I have everything in one main function right now, except for the function that is linked via the signal: mButton.signal_clicked().connect(sigc::ptr_fun(&addFunction))

*All of my variables are declared inside of the main method, I know not whether I would need to declare them outside of main, or if there is some trick with static variables/functions.

I know that the variables representing the Gtk::Entry are not within scope of the function that is called by the signal listener (is that the correct terminology for C++?) and I tried the dirty method of declaring them outside of main, but this caused all sorts of terrible errors.

Please help.

Name: Anonymous 2009-08-03 8:12

>>6
no u

Name: ​​​​​​​​​​ 2010-10-22 6:33

Name: Anonymous 2010-11-26 9:39

Name: Sgt.Kabu뮜kiman㷳猴 2012-05-28 21:20

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List