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

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 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.

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