gtkmm 将值传递给构造函数

问题描述 投票:0回答:0

我正在尝试在主 Gtk::Window 的 Gtk::Box 中设置一个包含不同数量的 Gtk::ToggleButtons 的向量,其数量将由程序开头的值确定。我不知道如何一路传递,此外还有以下

error: expected class-name before ‘{’ token
用于我的LeftBox类声明。我怎样才能使这项工作?

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>

class LeftBox : public Gtk::Box 
{
  public:
      LeftBox(short num_stops); //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 num_stops); //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(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;
}
c++ gtk gtkmm gtkmm4
© www.soinside.com 2019 - 2024. All rights reserved.