LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2007, 05:00 AM   #1
Tommassino
LQ Newbie
 
Registered: May 2007
Location: Czech Republic
Distribution: Gentoo
Posts: 1

Rep: Reputation: 0
Gtk delete_event handler problem


hi i am new to gtk programming, i am trying to make a "delete-event" signal handler, which would show a dialog with typical "Are you sure you want to quit?" but this only works for as a handler for button ("clicked" signal) i have on my program but not for above mentioned "delete_event" signal.when i am testing it as a "clicked" handler it works without problem but for a "delete_events" it shows these errors

Quote:
(foobar-sample:31870): GLib-GObject-WARNING **: invalid unclassed pointer in cast to `GtkDialog'

(foobar-sample:31870): Gtk-CRITICAL **: gtk_dialog_run: assertion `GTK_IS_DIALOG (dialog)' failed
this is my sorce code please try and try toadvice me
Quote:
#include <stdio.h>
#include <gtk/gtk.h>


/* Our new improved callback. The data passed to this function
* is printed to stdout. */
static gint run_dialog( GtkWidget *widget,
gpointer data )
{
gint result;
GtkWidget *dialog;
dialog=(GtkWidget *)data;
result=gtk_dialog_run(GTK_DIALOG(dialog));
switch(result){
case GTK_RESPONSE_ACCEPT:
printf("Answer YES\n");
gtk_main_quit();
gtk_widget_hide(dialog);
return FALSE;
break;
case GTK_RESPONSE_REJECT:
printf("Answer NO\n");
gtk_widget_hide(dialog);
return TRUE;
break;
}

}
int main( int argc,
char *argv[] )
{

GtkWidget *window;
GtkWidget *button;
GtkWidget *dialog;



gtk_init (&argc, &argv);



window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!");
gtk_window_set_default_size(GTK_WINDOW(window),320,240);
g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(run_dialog),dialog);

dialog = gtk_dialog_new_with_buttons ("My dialog",
NULL,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
NULL);


button=gtk_button_new_with_label("");
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(run_dialog),(gpointer) dialog);
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main ();

return 0;
}
 
Old 06-06-2007, 07:42 PM   #2
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
A demonstration of using the "delete-event" to show a quit confirmation dialog is here:
Confirm quit using dialog on the "delete-event"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 02:17 PM
problem in invoking interrupt handler for serial port in 2.4.21-ELsmp Redhat linux mrinal mishra Linux - Kernel 1 08-15-2006 02:52 PM
JavaScript: problem with onchange handler Robhogg Programming 1 05-20-2006 02:42 PM
Problem in interrupt handler for uart 16550 mrinal mishra Linux - Kernel 3 05-05-2006 12:00 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration