callback function

This is a discussion on callback function within the C Programming forums, part of the General Programming Boards category; Hi, I begun my gtk+ programming in C and I thought it could be fun to "develop some tutorials further" ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    callback function

    Hi, I begun my gtk+ programming in C and I thought it could be fun to "develop some tutorials further" so I took the interface from a tutorial and wanted to connect callback functions to the buttons. Here is my code...
    Code:
    /*definition of a structure that hold all the parameters I want to send to callback function*
    typedef struct
    {
        int cisliceee;
        GtkWidget*nalepka;
            int poziceee;
    }vstup;
    //declaration of an array of those structures//
    vstup*v[16];
    /*main callback function called by all the buttons, what will happen is to be 
    determined by the content of the structure that is passed as an argument, I think
     my whole problem might be in the pointer to v object*/
    void cudl_stisknut(GtkWidget *widget, vstup*v)
    {   if (v->poziceee=8){
        gtk_main_quit();}
       
    }
    }
    ...
    int main(int argc, char* argv[]){
    ...
    /*things used to build up the GUI*/
    GtkWidget *cudl[16];
    
      char *hodnoty[16] = { "1", "2", "3", "/",
         "4", "5", "6", "*",
         "7", "8", "9", "-",
         "0", ".", "=", "+"
      };
    /*implementation of v array*/
    int iks;
        for( iks=0; iks<16; iks++) {
            v[iks]= g_slice_new (vstup);
        }
    /*function to construct a GUI table as well as store necessary arguments in v structure*/
    int i = 0;
      int j = 0;
       int pozice = 0;
         for( i=0; i < 4; i++) {
        for( j=0; j < 4; j++) {
         cudl[pozice] = gtk_button_new_with_label(hodnoty[pozice]);
           
    cislice[pozice]= atoi(hodnoty[pozice]);
            v[pozice]->cisliceee=cislice[pozice];
            v[pozice]->nalepka=vysledkovy_radek;
            v[pozice]->poziceee=pozice;
    {      gtk_table_attach_defaults(GTK_TABLE(ciselnice), cudl[pozice], j, j+1, i, i+1 );
          pozice++;
        }
      }
    }
    /*and finally connecting the signal (the same one) to all the buttons*/
    for (pozice=0; pozice < 16; pozice++){
        g_signal_connect(G_OBJECT(cudl[pozice]), "clicked",
         G_CALLBACK(cudl_stisknut), (gpointer) v[pozice]);
    }
    NOW the big problem is that not only clicking cudl[8] which passes with its signal structure v[8] that holds v[8]->poziceee=8 causes TRUE in the condition of the callback function and therefore gtk_main_quit BUT ALSO ALL THE OTHER BUTTONS!!!. I spent a lot of time trying to make it work, but no matter the condition in cudl_stisknut() is always taken as true no matter which button I press...
    I hope that somebody can help... thank you a lot

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    if (v->poziceee==8){

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    typo as always

    I dont know if you ever thought about it but I think that about 99% of my programming mistakes are just mere typos.
    by the way ... thanks a lot... I was getting insane and you know the state when you just go through the code 10 times and find nothing except that you are looking for a GIANT problem but in fact it is tiny tiny thing that is missing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. callback function v. regular function
    By 7stud in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2005, 11:34 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Is it possible to have callback function as a class member?
    By Aidman in forum Windows Programming
    Replies: 11
    Last Post: 08-01-2003, 12:45 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21