Accessing combo box text

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Accessing combo box text

deepak.bhujangachar

Hi All,

I am using Glade 3.0 and GTKMM. I am trying to access Combo box text  
and id. I am failing in it. I pasted a code I did. Please help in  
accessing Combo box attributes.

//This is the signal

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

//Trying to access ID

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

Thanks
Deepak


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing combo box text

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



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing combo box text

deepak.bhujangachar
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 <[hidden email]>:

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



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing combo box text

Daniel Boles
You only connect the signal handler that does the print, if the Builder returned a non-null pointer. Have you checked whether the Builder actually returns a non-null pointer, i.e. successfully looks up the widget with name Product_Combo to m_combo!?

I would recommend, as always, assert()ing that all points are non-nullptr before dereferencing them, and if possible compiling with UBsan so that it can often catch that if you don't.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing combo box text

Daniel Boles
In reply to this post by deepak.bhujangachar

On 22 July 2017 at 12:07, <[hidden email]> wrote:
Hi All,

I am getting message like this after stop debugging. "gtkmm-CRITICAL **: gtkmm: object `Product_Combo' not found in GtkBuilder file." Please help.

Thanks
Deepak

Well? Is it in the ui file? Despite your many messages indicating that you think people here are psychic, they are not.

I mean, look at what you've asked. What are we meant to do with that? Psychically tell you what is wrong with this mysterious .ui file you haven't shown us?

Again, please spend more time thinking about how to ask usable questions. You can't just keep posting here saying 'I tried this, but it doesn't work. What is wrong' and no more info that that. It doesn't provide any fuel for discussion, and frankly it's starting to feel like spam.



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing combo box text

Murray Cumming-5
On Sat, 2017-07-22 at 12:23 +0100, Daniel Boles wrote:

>
> On 22 July 2017 at 12:07, <[hidden email]>
> wrote:
> > Hi All,
> >
> > I am getting message like this after stop debugging. "gtkmm-
> > CRITICAL **: gtkmm: object `Product_Combo' not found in GtkBuilder
> > file." Please help.
> >
> > Thanks
> > Deepak
>
> Well? Is it in the ui file? Despite your many messages indicating
> that you think people here are psychic, they are not.
>
> I mean, look at what you've asked. What are we meant to do with that?
> Psychically tell you what is wrong with this mysterious .ui file you
> haven't shown us?
>
> Again, please spend more time thinking about how to ask usable
> questions. You can't just keep posting here saying 'I tried this, but
> it doesn't work. What is wrong' and no more info that that. It
> doesn't provide any fuel for discussion, and frankly it's starting to
> feel like spam.

Daniel, please be more patient if you choose to respond. This person is
asking for help. Your first two sentences would have been enough.

If you also want to teach him how to ask, please be nicer about it.


--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Loading...