How to use gtk combo
box
You know that how to place widgets on the window in glade.
So I will demonstrate to setup combo box directly.
Step 1:
Step 2:
After clicking new glade will
add liststore in your window
See example below
Step 3: click on the
liststore1
After doing this you will see
like you see in below image
Step 4:
Step 5:
Step 6:
When you click add button in the above window
Then do like in below image
Now close this window and save the work.
Now the coding part.
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
struct window
{
GtkComboBox *cb;
GtkLabel *l;
};
typedef struct window Widgets;
Widgets Widg;
G_MODULE_EXPORT void on_GetAndSet_clicked ( GtkButton
*button,Widgets *widg)
{
const gchar *text =
gtk_combo_box_get_active_text( widg->cb ); // getting text from the combo box
gtk_label_set_text(Widg.l,text); /*setting or you can say
putting text on the label so that you can se
what
you have selected in the combo box*/
}
// and till from the beginning of gtk tutorial now you
obviously know what to do in the main now I will not comment below code. J
int main(int argc, char *argv[])
{
GtkBuilder
*gtkBuilder;
GtkWidget *win;
gtk_init(&argc, &argv);
gtkBuilder =
gtk_builder_new();
gtk_builder_add_from_file(gtkBuilder, "cb.glade", NULL);
win = GTK_WIDGET(
gtk_builder_get_object( gtkBuilder, "window1") );
Widg.cb =
GTK_COMBO_BOX( gtk_builder_get_object( gtkBuilder, "combobox1" ) );
Widg.l =
GTK_LABEL( gtk_builder_get_object( gtkBuilder, "label" ) );
gtk_builder_connect_signals( gtkBuilder,&Widg );
g_object_unref(G_OBJECT(gtkBuilder));
gtk_widget_show(win);
gtk_main();
return 0;
}
I am facing this error while build and run :
ReplyDelete"the procedure entry point g byte get type could not be located in the dynamic link library libgobject-2.0-0.dll"