Re: GTK_IS_ENTRY failed
- From: "Nils O." Selåsdal <noselasd frisurf no>
- To: Thomas Ugland <killer lothlorien no>
- Cc: GTK Application Developement List <gtk-app-devel-list gnome org>
- Subject: Re: GTK_IS_ENTRY failed
- Date: 28 Jun 2002 21:12:00 +0200
On Fri, 2002-06-28 at 16:09, Thomas Ugland wrote:
I'm not sure if this is just a problem with my C skills (inwich isnt
very good yet), or something else. But I anyways try my luck here to see
if anyone can help me out :)
I'm making a GUI that works against a MySQL database. In the initial
start I make a config file, if it doenst exist, fetching various info
(login, pass, etc).
If you see the attached C file you will find that i use an
GtkWidget *entry[4];
make new entry box'es on them. This works fine and they show up fine in
the gtk window, but when I try to use
gtk_entry_get_text(GTK_ENTRY(entry[0])); it manages to fetch the text
from the first 4 entry box'es, but the 5th (entry[4]) it errors with:
(a.out:10441): GLib-GObject-WARNING **: invalid cast from `GtkButton' to
`GtkEntry'
(a.out:10441): Gtk-CRITICAL **: file gtkentry.c: line 3421
(gtk_entry_get_text): assertion `GTK_IS_ENTRY (entry)' failed
my bad? or something else?
Any help appreciated.. :)
--
Thomas Ugland
-> If everything is coming your way then you're in the wrong lane. <-
----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
GtkWidget *make_entry_with_label(GtkTable *table, const gchar *label_text, gint left_attach, gint
right_attach, gint top_attach,
gint bottom_attach, gint entry_length);
gint config_gui(void);
void action(GtkWidget *entry[]);
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
config_gui();
return 0;
}
void action(GtkWidget *entry[])
{
printf("H: %s\n", gtk_entry_get_text(GTK_ENTRY(entry[0])));
printf("U: %s\n", gtk_entry_get_text(GTK_ENTRY(entry[1])));
printf("P: %s\n", gtk_entry_get_text(GTK_ENTRY(entry[2])));
printf("D: %s\n", gtk_entry_get_text(GTK_ENTRY(entry[3])));
printf("T: %s\n", gtk_entry_get_text(GTK_ENTRY(entry[4])));
}
GtkWidget *make_entry_with_label(GtkTable *table,
const gchar *label_text,
gint left_attach,
gint right_attach,
gint top_attach,
gint bottom_attach,
gint entry_length)
{
GtkWidget *entry;
GtkWidget *label;
label = gtk_label_new(label_text);
entry = gtk_entry_new();
gtk_table_attach(table, label, left_attach, right_attach, top_attach, bottom_attach, GTK_FILL,
GTK_EXPAND, 5, 5);
gtk_table_attach(table, entry, left_attach + 1, right_attach + 1, top_attach, bottom_attach, GTK_FILL,
GTK_EXPAND, 5, 5);
gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
gtk_misc_set_padding(GTK_MISC(label), 2, 2);
gtk_entry_set_max_length(GTK_ENTRY(entry), entry_length);
gtk_widget_show(entry);
gtk_widget_show(label);
return entry;
}
gint config_gui()
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *bbox;
GtkWidget *button;
GtkWidget *entry[4];
Here you declare an array to hold 4 elements.
GtkWidget *frame;
GtkWidget *table;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Database login configuration");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(GTK_WINDOW(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
frame = gtk_frame_new("Database login configuration:");
vbox = gtk_vbox_new(FALSE, 5);
table = gtk_table_new(4,2, FALSE);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(frame), table);
entry[0] = make_entry_with_label(GTK_TABLE(table), "Hostname:", 0,1,0,1,32);
entry[1] = make_entry_with_label(GTK_TABLE(table), "Username:", 0,1,1,2,15);
entry[2] = make_entry_with_label(GTK_TABLE(table), "Password:", 0,1,2,3,15);
gtk_entry_set_visibility(GTK_ENTRY(entry[2]), FALSE);
entry[3] = make_entry_with_label(GTK_TABLE(table), "Database:", 0,1,3,4,15);
entry[4] = make_entry_with_label(GTK_TABLE(table), "Table:", 0,1,4,5,15);
And here you element at location 5. In an array[4] you only have 0,1,2,3
that's 4 elements, make room for the fift in the declaration above.
bbox = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 3);
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(bbox), 10);
button = gtk_button_new_from_stock(GTK_STOCK_OK);
gtk_container_add(GTK_CONTAINER(bbox), button);
g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(action), entry);
button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(bbox), button);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
--
Nils Olav Selåsdal <NOS Utel no>
System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]