Reputation: 941
I am trying to set up a vector of a varying amount of Gtk::ToggleButtons in a Gtk::Box of the main Gtk::Window, the amount of which would be determined by a value at the beginning of the program. I don't know how to pass it all the way through without errors.
At the moment there is an error: no matching function for call to LeftBox::LeftBox()
despite it having a defined constructor.
main.cc:
#include "helloworld.h"
#include <gtkmm/application.h>
int main(int argc, char* argv[])
{
auto app = Gtk::Application::create("org.gtkmm.example");
/* ideally program will execute query to find out how many stops on left, right, + how
much pistons, and then use this value in the constructor LeftWindow or smthng like that*/
short num_stops = 5;
//Shows the window and returns when it is closed.
return app->make_window_and_run<LeftWindow>(argc, argv, num_stops);
}
helloworld.h:
#ifndef LCS_APP
#define LCS_APP
#include <gtkmm/button.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/window.h>
#include <gtkmm/box.h>
class LeftBox : public Gtk::Box
{
public:
LeftBox(short); //class constructor
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
Gtk::ToggleButton m_button; //a tab or piston, will probably have to create sub classes for each
//To-Do: variable amount of buttons, i.e.
std::vector<Gtk::ToggleButton> lstop_vector;
};
class LeftWindow : public Gtk::Window
{
public:
LeftWindow(short); //is the constructor for this class
//~HelloWorld() override;
protected:
//Signal handlers:
//Member widgets:
LeftBox leftbox;
};
#endif
helloworld.cc:
#include "helloworld.h"
#include <iostream>
LeftWindow::LeftWindow(short num_stops) {
leftbox(num_stops);
set_child(leftbox);
}
std::string nums[10] = {"1","2","3","4","5","6","7","8","9","10"};
LeftBox::LeftBox(short num_stops) {
m_button("Hello World");
// Sets the margin around the button.
m_button.set_margin(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&LeftWindow::on_button_clicked));
// This packs the button into the Box (a container).
set_child(m_button);
int i;
if (num_stops <= 10) {
for (i = 0; i < num_stops; i++) {
Gtk::ToggleButton stop(nums[i]);
lstop_vector.push_back(stop);
}
}
append(lstop_vector);
}
void LeftBox::on_button_clicked()
{
std::cout << "Hello World" << std::endl;
}
Upvotes: 1
Views: 155