Hi, I can now see why you are getting confused. In these examples the programmer has called the member functions "virtual" so that they could be over ridden. But in this case they are not over ridden and do not over ride any other member function. In the new tutorial for GTKmm 3 these examples have been written with-out the use of "virtual". I think to make it clearer for beginners.
class ExampleWindow : public Gtk::Window
virtual void on_button_quit();
virtual void on_notebook_switch_page(GtkNotebookPage* page, guint page_num);
Gtk::Label m_Label1, m_Label2;
This header defines our class "ExampleWindow" which if derived from "Gtk::Window", so it gains all the properties of a Gtk::Window plus what ever is defined in this class . There are two public member functions, the constructor and the destructor. The destructor is virtual so that at destruction time the destructor for ExampleWindow is first called then the destructor Gtk::Window.
Within the protected section there are two member functions that are our signal handlers. They are defined as virtual here, but do not need to be and do not over ride anything here. The names of these functions could be anything, but the number and types of arguments must match the signal they would be connected to. Also defined are various widgets which would be constructed before our constructor code is called.
: m_Label1("Contents of tab 1"),
m_Label2("Contents of tab 2"),
//Add the Notebook, with the button underneath:
//Add the Notebook pages:
void ExampleWindow::on_notebook_switch_page(GtkNotebookPage* /* page */, guint page_num)
std::cout << "Switched to tab with index " << page_num << std::endl;
//You can also use m_Notebook.get_current_page() to get this index.
Even before we enter the code for our constructor the default constructor for two of the labels and a button is changed so that the text is set. The rest of the code sets properties and places the widgets to create the user interface, connects the two signals and shows all the child widgets of the window.
This is the code that connects the "clicked" signal of the Gtk::Button.
Our widget is m_Button_Quit and is a Gtk::Button. This has a member function called signal_clicked() which in turn has a member function called connect(const SlotType& slot, bool after=true). Here we ignore the second argument to connect as using the default is what is nearly always needed and saves typing. To create the "slot" the function used is sigc::mem_fun(obj, someclass::somemethod). Here the first argument is "*this" and says that our signal handler will use this class object. The second argument is the address of ExampleWindow::on_button_quit() and will be the signal handler to be called when the button is clicked on. Note that the number and types of arguments of the signal handler must match that of the signal or the compiler will give errors.
The code to connect the other signal follows a similar pattern.
To find out what arguments are passed you will need to look at the documentation.
Glib::SignalProxy0< void > Gtk::Button::signal_clicked ()
This shows that signal_clicked does not receive any arguments and does not return any value.
GtkNotebookPage*, guint > Gtk::Notebook::signal_switch_page ()
This shows that signal_switch_page receives twos arguments - GtkNotebookPage * and guint and does not return any value.
The destructor for ExampleWindow does nothing apart from the default destruction of its members (the widgets) followed by Gtk::Window.
The signal handlers are fairly simple. void ExampleWindow::on_button_quit() is called when the button with the label "Quit" is clicked. This calls hide() which hides the window and hence exits the Gtk main loop.
The signal handler void ExampleWindow::on_notebook_switch_page(GtkNotebookPage* /* page */, guint page_num) is called when the currently selected page is changed. Here the first argument is ignored and its use is deprecated and its type and meaning changes in GTK 3. The second argument is the page number of the notebook widget that is now selected. This value is printed with a message to std::cout.
int main(int argc, char *argv)
Gtk::Main kit(argc, argv);
//Shows the window and returns when it is closed.
This is the main function which creates the Gtk::Main, then our window with its widgets then runs it all until the window is closed or hidden.
That's part 1 done. I do hope that helps you. This shows you one way of connecting signals under GTKmm. Signals under GTKmm is fairly complex as there is so much that you can do with them, plus the addition of connecting via over riding virtual member function. Also for those that are new to GTK in general where the arguments come from can at first be confusing, it does not matter what programming language you are using.
Part 2 - hopefully later today.