Re: Question aboutusing message dialog to ask confirmation



On Fri, 16 May 2008 19:19:55 +0100 John M Collins wrote:

I want to have a "do you really want to do this" type question and I'm
trying to use a message dialog thus:

GtkWidget  *dlg = gtk_message_dialog_new(GTK_WINDOW(previous),
GTK_DIALOG_DESTROY_WITH_PARENT,
 GTK_MESSAGE_QUESTION,
 GTK_BUTTONS_YES_NO, "Are you sure?");
g_signal_connect_swapped(dlg,
  "response", G_CALLBACK(gtk_widget_destroy), dlg);

Then I put

if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_YES)  {

      /* Do the thing we asked about */
}
else  {
      /* Get out of here */
}


the return value from gtk_dialog_run is never GTK_RESPONSE_YES, it's
always zero whether the Yes or No button is clicked.

gtk_dialog_run() also connects to the 'response' signal.  You cannot
rely on signal callbacks being called in any particular order.  In your
case, likely your handler (gtk_widget_destroy()) is getting called
before gtk_dialog_run()'s response handler, so you destroy the widget
before the gtk_dialog_run() response handler can run.

        -brian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]