I've been working on GUI programming, using the GTK+ API. It's been great fun, though I've run into a frustrating problem I can't wrap my head around.
I will lightly go over the GTK+ API, as I discuss my problem.
The copy/paste functions take 2 arguments, one is the desired string to copy, and the other is the clipboard object.
This function will execute when the user hits CTRL+C
Now, the first argument is the widget that is calling this function. When calling a function you must pass a pointer to the widget, as well as one other argument. This makes it rather difficult because my callback function requires two arguments - a string, and a clipboard object.Code:void copythis(GtkWidget *w, CCP *stuff) { gtk_text_buffer_copy_clipboard(stuff->buf, stuff->clip); }
Therefore I create a struct, that will allow me to hold both of these variables
Now here are my variable initializations in the main function.Code:typedef struct copycutpaste CCP; struct copycutpaste { GtkTextBuffer *buf; GtkClipboard *clip; };
Finally my callback functionCode:GtkTextBuffer *buffer; GtkClipboard *board; CCP copying = {buffer, board}; CCP pasting = {buffer, board}; CCP cutting = {buffer, board};
"G_OBJECT(copy)" is a menu item widget. Whenever the user clicks "copy" in the menu this function will execute. "G_CALLBACK(copythis)" is the function to call on, and "©ing" is the argument that is passed.Code:g_signal_connect(G_OBJECT(copy), "activate", G_CALLBACK(copythis), ©ing);
Now, the code compiles without warnings, however I am getting segmentation faults whenever the function "copythis" is executed. I've looked over this for so long, and I can't pick out whats wrong with it. Any help would be much appreciated, I hope I've explained it well enough. If you need clarification on any function just ask.



LinkBack URL
About LinkBacks


