gtkmm ToggleButton help
Nov 2, 2020 at 6:34am UTC
I am following a beginner tutorial on gtkmm, and the online tutorial doesn't really explain things like how to create widgets. It just explains to you what each widget is, but doesn't provide a code example so I'm left with looking at the documentation.
I am trying to create a simple ToggleButton that will output whether it is active or inactive. If I press the ToggleButton, it will output to the console "ToggleButton active", else if the ToggleButton is pressed again, it will output to the console "ToggleButton inactive". This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include <iostream>
#include <gtkmm/application.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/window.h>
using namespace std;
class ToggleButtons: public Gtk::Window
{
public :
ToggleButtons();
virtual ~ToggleButtons();
protected :
// Signal handler for ToggleButton
void togglebutton_toggler(Gtk::ToggleButton *tgbtn);
// Create the ToggleButton
Gtk::ToggleButton t_button;
};
ToggleButtons::ToggleButtons()
{
// Decorate window
set_title("ToggleButton" );
set_default_size(300, 150);
t_button.set_label("Toggle Button" );
t_button.set_margin_left(30);
t_button.set_margin_right(30);
t_button.set_margin_top(30);
t_button.set_margin_bottom(30);
// Sets the event listener for the ToggleButton
t_button.signal_toggled().connect(sigc::bind(sigc::slot(*this , &ToggleButtons::togglebutton_toggler), t_button));
// Add the togglebutton to the window
add(t_button);
// Show all widgets in the window
show_all_children();
}
ToggleButtons::~ToggleButtons() { }
void ToggleButtons::togglebutton_toggler(Gtk::ToggleButton *tgbtn)
{
if (tgbtn->get_active())
cout << "ToggleButton active!" << endl;
else
cout << "ToggleButton inactive!" << endl;
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "gtkmm tuts" );
ToggleButtons tgbtn;
// Shows the window and returns when it's close
return app->run(tgbtn);
}
This is the line I'm getting an error with:
t_button.signal_toggled().connect(sigc::bind(sigc::slot(*this , &ToggleButtons::togglebutton_toggler), t_button));
And the error says: "gtkmm.cpp:36:59: error: missing template arguments before ‘(’ token
36 | t_button.signal_toggled().connect(sigc::bind(sigc::slot(*this, &ToggleButtons::togglebutton_toggler), t_button));"
What's going on?
Nov 2, 2020 at 3:26pm UTC
Topic archived. No new replies allowed.