Re: Accessing combo box text



Sir,

Here I am not getting any errors. But I am unable to print the row number in the Console. I followed the steps as in documentation. I am posting code again with .cpp and .h files. Do I need to instantiate entry also. Please help.

derived_window.h

#ifndef DERIVED_LOGIN_SCREEN_H_
#define DERIVED_LOGIN_SCREEN_H_

#include <gtkmm.h>
#include <gtkmm-3.0/gtkmm/liststore.h>
#include <gtkmm-3.0/gtkmm/combobox.h>

class mainWindow : public Gtk::Window
{
public:
mainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
  virtual ~mainWindow();

protected:
  void combo_product_changed();
  void combo_variant_changed();

  Glib::RefPtr<Gtk::Builder> m_refGlade;
  Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
  Gtk::ComboBox* m_Combo1;
  Gtk::ComboBox* m_Combo2;
};

#endif /* DERIVED_LOGIN_SCREEN_H_ */

#include "derived_login_screen.h"
#include <gtkmm.h>
#include <iostream>
#include <gtkmm-3.0/gtkmm/box.h>
#include <gtkmm-3.0/gtkmm/window.h>

derived_window.cpp

mainWindow::mainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
: Gtk::Window(cobject),
  m_refGlade(refGlade),
  m_Combo1(nullptr), m_Combo2(nullptr)
{
  //Get the Glade-instantiated Button, and connect a signal handler:
  m_refGlade->get_widget("Product_Combo", m_Combo1);  // widget names
  m_refGlade->get_widget("Variant_Combo", m_Combo2);

 if(m_Combo1)
 {
m_Combo1->signal_changed().connect( sigc::mem_fun(*this, &mainWindow::combo_product_changed));
 }

 if(m_Combo2)
 {
m_Combo2->signal_changed().connect( sigc::mem_fun(*this, &mainWindow::combo_variant_changed));
 }

    show_all_children();

}

mainWindow::~mainWindow()
{
  //Dtor
}

void mainWindow::combo_product_changed()
{
      int product = m_Combo1->get_active_row_number();
      std::cout << "Combo changed: " << product << std::endl;
}

Thanks
Deepak

Quoting Daniel Boles <dboles src gmail com>:

You are failing how? What is the error? Please, try to post questions that
give readers a bare minimum of info to work with.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]