Visit The New, Modern Unix Linux Community


Error compiling GTK Accelerator (C programming)


 
Thread Tools Search this Thread
Top Forums Programming Error compiling GTK Accelerator (C programming)
# 1  
Error compiling GTK Accelerator (C programming)

I believe this may be a difference in GTK+-2.0 and GTK+-3.0. I followed this tutorial and ended up with this error:

Code:
# gcc -Wall -g mnemonics.c -o mnemonics `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`
mnemonics.c: In function ‘main':
mnemonics.c:44:61: error: ‘GDK_q' undeclared (first use in this function)
mnemonics.c:44:61: note: each undeclared identifier is reported only once for each function it appears in

I double-checked and I have all the correct header files installed in the correct locations.

Here is my code:
Code:
#include <gtk/gtk.h>                                                                                                                                                                
#include <gdk/gdkkeysyms.h>                                                                                                                                                         
                                                                                                                                                                                    
int main(int argc, char *argv[])                                                                                                                                                    
{                                                                                                                                                                                   
                                                                                                                                                                                    
  GtkWidget *window;                                                                                                                                                                
  GtkWidget *vbox;                                                                                                                                                                  
                                                                                                                                                                                    
  GtkWidget *menubar;                                                                                                                                                               
  GtkWidget *filemenu;                                                                                                                                                              
  GtkWidget *file;                                                                                                                                                                  
  GtkWidget *new;                                                                                                                                                                   
  GtkWidget *open;                                                                                                                                                                  
  GtkWidget *quit;                                                                                                                                                                  
                                                                                                                                                                                    
  GtkWidget *sep;                                                                                                                                                                   
                                                                                                                                                                                    
  GtkAccelGroup *accel_group = NULL;                                                                                                                                                

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
  gtk_window_set_title(GTK_WINDOW(window), "menu");

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);

  // In this code we create a menubar and a menu.
  menubar = gtk_menu_bar_new();
  filemenu = gtk_menu_new();

  accel_group = gtk_accel_group_new();
  gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);

  file = gtk_menu_item_new_with_mnemonic("_File");
  new = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL);
  open = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, NULL);
  sep = gtk_separator_menu_item_new();
  quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);

  gtk_widget_add_accelerator(quit, "activate", accel_group, GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  // The code line below implements a file menu
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  // Here menu items are implemented
  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), new);
  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), sep);
  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), NULL);

  g_signal_connect(G_OBJECT(quit), "activate",
        G_CALLBACK(gtk_main_quit), NULL);

  gtk_widget_show_all(window);

  gtk_main();

  return 0;

}

# 2  
It looks like a typo on their part.

It's not defined as GDK_q, it's defined as GDK_Q
This User Gave Thanks to Corona688 For This Post:
# 3  
Did you mean to use GDK_KEY_q instead of GDK_q ?

Code:
gtk_widget_add_accelerator(quit, "activate", accel_group, GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

This User Gave Thanks to Quintab For This Post:
# 4  
GDK_KEY_q worked for me, GDK_Q did not. Perhaps its the difference in 2.0 vs 3.0? None the less, that was a very nice link Corona688 pointed to.

Thank you both!

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #153
Difficulty: Easy
Novell sold their Unix business operations to Microsoft in 1995.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error while compiling

Hi I am trying to compile a binary file (CASPER: Context-Aware Scheme for Paired-End Read) but I am getting the following error: user@user-OptiPlex-780 make g++ -O2 -Wall -fopenmp -c -o merge.o merge.c merge.c:8:35: fatal error: boost/unordered_map.hpp: No such... (2 Replies)
Discussion started by: Xterra
2 Replies

2. Solaris

ERROR while compiling

Hi guys i came across an error while compiling a c file in solaris using gcc. the error is, Undefined first referenced symbol in file bind /var/tmp//ccAr8qAh.o accept ... (4 Replies)
Discussion started by: rajeshb6
4 Replies

3. Programming

Error with compiling

Hi guys. I have a header file: unp.h like this: #ifndef _UNP_H_ #define _UNP_H_ extern ssize_t readn(int filedes, void *buff, size_t nbytes); extern ssize_t writen(int filedes, const void *buff, size_t nbytes); extern void err_quit(const char *msg); #define TRUE 1 #define FALSE 0 ... (2 Replies)
Discussion started by: majid.merkava
2 Replies

4. UNIX for Dummies Questions & Answers

Error in terminal: Gtk-CRITICAL

Hi, I am using Ubuntu 10.04. Recently I have seen this error appear in my terminal as I edit text files with gedit: (gedit:2841): Gtk-CRITICAL **: gtk_widget_is_ancestor: assertion `ancestor != NULL' failed Any ideas on what this means? Mike (1 Reply)
Discussion started by: msb65
1 Replies

5. Programming

gcc compiling error

I am using gcc to compile c objects on solaris 5.10 and hit the following error messages: /usr/include/sys/vfs.h:323: error: syntax error before "statvfs64_t" /usr/include/sys/vfs.h:334: error: syntax error before "statvfs64_t" gmake: *** Error 1 The c program files were copied over from... (3 Replies)
Discussion started by: med7006
3 Replies

6. Red Hat

DirectFb installation & accelerator not recognised

Hi, I installed DirectFb on fedora 7, the machine has a Nvidia graphics card. The installation was successful and I can play the examples provided by the Direct fb website, but, I find that the accelarator is not getting recognised. when I do "fbset -i", the details shown are as below, it gives... (0 Replies)
Discussion started by: sifar
0 Replies

7. Programming

pipes : error on compiling!

Hi All. I have one problem. I am writng client-server by using pipes. But when i compile i get following error. /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crt1.o(.text+0x18): In function `_start': : undefined reference to `main' collect2: ld returned 1 exit status make: *** Error 1 ... (2 Replies)
Discussion started by: i.pas
2 Replies

8. Programming

Compiling Error

Hi, I have installed "Freetype2" library in my SuSe Linux 9.3 version system. When Iam compiling a program, I am getting these below errors. Undefined reference to "FT_Init_FreeType" Undefined reference to "FT_Load_Char" Please show me a solution? Thank you. With regards, Chandramouli (1 Reply)
Discussion started by: chandra80
1 Replies

9. UNIX for Dummies Questions & Answers

Installing a modem on a serial accelerator ports

I had been using a modem installed on a Digi accelerator port to dial in to an SCO open server r5 server. On monday it quit working and I realy don't know how it was installed and configured. I have tested the modem on a PC and it works. The port the modem is connected to is ttyB06 and I have... (1 Reply)
Discussion started by: kikkin
1 Replies

Featured Tech Videos