GtkComboBoxEntry Vs GtkComboBox
- From: "Peter E Dennis" <peter edwin dennis gmail com>
- To: gtk-app-devel-list gnome org
- Subject: GtkComboBoxEntry Vs GtkComboBox
- Date: Tue, 22 Jan 2008 21:55:15 +1100
Hi All,
I have the following code that I copied from the hello world part of
the GTK+ tutorial. I used it to practice using GtkComboBoxEntry(s).
#include <gtk/gtk.h>
int main( int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *cboVocSource;
/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application. */
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Creates a new combo box entry with the text Hello World */
cboVocSource = gtk_combo_box_entry_new_text ();
gtk_widget_set_name (cboVocSource, "cboVocSource");
gtk_combo_box_append_text(cboVocSource, "Hello World");
/* This packs the button into the window (a gtk container). */
gtk_container_add (GTK_CONTAINER (window), cboVocSource);
/* The final step is to display this newly created widget. */
gtk_widget_show (cboVocSource);
/* and the window */
gtk_widget_show (window);
/* All GTK applications must have a gtk_main(). Control ends here
* and waits for an event to occur (like a key press or
* mouse event). */
gtk_main ();
return 0;
}
I compile it with the following command:
$ gcc -Wall -g box.c -o box `pkg-config --cflags gtk+-2.0` `pkg-config
--libs gtk+-2.0`
And get this warning:
box.c: In function 'main':
box.c:23: warning: passing argument 1 of 'gtk_combo_box_append_text'
from incompatible pointer type
In the api it has the definition for gtk_combo_box_append_text as:
void gtk_combo_box_append_text (GtkComboBox *combo_box,
const gchar *text);
So I wondered if I needed to cast my GtkComboBoxEntry to a GtkComboBox
but wasn't sure how to do this so I tried:
gtk_combo_box_append_text(GTK_COMBO(cboVocSource), "Hello World");
This however makes matters worse as I get the above warning still when
I compile it, but now when I run it I get:
$ ./box
(box:11338): GLib-GObject-WARNING **: invalid cast from
`GtkComboBoxEntry' to `GtkCombo'
Can someone please tell me what I'm doing wrong?
Many thanks,
Peter.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]