0

I'm trying to create a dialog that pops up when the user selects a specific entry from the combobox, it should record the user input and react accordingly.

here's my code so far:

void add_new_set(GtkWidget entry) { g_print("howdy\n"); } GtkWidget * dialog = gtk_dialog_new_with_buttons("Message",container,GTK_DIALOG_DESTROY_WITH_PARENT,"OK", GTK_RESPONSE_NONE,NULL); GtkWidget * content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); GtkWidget * entry = gtk_entry_new(); gtk_container_add(GTK_CONTAINER(content_area), entry); g_signal_connect_swapped (dialog,"response",G_CALLBACK (add_new_set),dialog); gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); gtk_widget_show_all (dialog); 

I need to get the input from the gtk_entry when the OK button is pressed, and perform a string comparison on that function. the g_print line runs when the button is pressed.

thanks

1 Answer 1

3

First, that is absolutely the wrong signature for add_new_set(). Not only does it not follow the correct signature for GtkDialog::response, but it also passes a GtkWidget as a parameter. You should never have GtkWidget by itself, always GtkWidget * (a pointer to GtkWidget).

The correct signature for a GtkDialog::response is given in the documentation:

void user_function (GtkDialog *dialog, gint response_id, gpointer user_data) 

Second, you will need a way to pass entry in via user_data, either directly or indirectly, and for that g_signal_connect_swapped() is wrong. Use g_signal_connect() instead; the last argument of that becomes the user_data.

Finally, the function to get the text out of a GtkEntry is called, obviously enough, gtk_entry_get_text(). The pointer returned is only valid in the signal handler itself; you will need to copy it if you want to access it later, but for your needs you won't need to.

Good luck.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.