Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3808438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:08:51+00:00 2026-05-19T15:08:51+00:00

// gcc 1.c -o 0 $(pkg-config –cflags –libs gtk+-2.0) #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> struct

  • 0
// gcc 1.c -o 0 $(pkg-config --cflags --libs gtk+-2.0)
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
struct tst
{
    GtkWidget *win, *vb, *ent, *btn, *lbl;
    GtkAccelGroup *acc;
    GClosure *cls;
};
static void print_val(int nmb)
{
    g_printf("%d\n", nmb);
}
static void window_new()
{
    struct tst *prg = g_new0(struct tst, 1);
    prg->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    prg->vb = gtk_vbox_new(TRUE, 0);
    prg->ent = gtk_entry_new();
    prg->btn = gtk_button_new_with_label("Print!");
    prg->lbl = gtk_label_new("Enter the string.");
    prg->acc = gtk_accel_group_new();
    int nmb = 140;
    prg->cls = g_cclosure_new(G_CALLBACK(print_val), nmb, NULL);
    gtk_container_add(GTK_CONTAINER(prg->win), GTK_WIDGET(prg->vb));
    gtk_box_pack_start(GTK_BOX(prg->vb), GTK_WIDGET(prg->ent), FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(prg->vb), GTK_WIDGET(prg->btn), FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(prg->vb), GTK_WIDGET(prg->lbl), FALSE, FALSE, 0);
    g_signal_connect(prg->win, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(prg->btn, "clicked", G_CALLBACK(print_val), (gpointer)nmb);
    gtk_window_set_title(GTK_WINDOW(prg->win), "Enter the string");
    gtk_window_add_accel_group(GTK_WINDOW(prg->win), prg->acc);
    gtk_accel_group_connect(prg->acc, GDK_KEY_P, (GDK_CONTROL_MASK | GDK_SHIFT_MASK), GTK_ACCEL_MASK, prg->cls);
    gtk_widget_show_all(GTK_WIDGET(prg->win));
}
int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    window_new();
    gtk_main();
    return 0;
}

I want to make this program to print 140 on console every time I pressed the button or Ctrl + Shift + P.

But this program prints the weird value(not 140) when I pressed the button or Ctrl + Shirt + P.

What should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:08:51+00:00Added an answer on May 19, 2026 at 3:08 pm

    Your print_val callback needs to have the correct number of parameters. If you look up the GtkButton::clicked signal in the GTK documentation, you will see it has this signature:

    void user_function (GtkButton *button, gpointer user_data)
    

    So the first parameter passed to print_val when you click the button is the address of the button itself. This is the “weird value” you are printing.

    Contrary to Jens’ answer here, GLib does provide a portable way to cast an int to a pointer. So to achieve what you want, you need to connect your signal like this:

    g_signal_connect(prg->btn, "clicked", G_CALLBACK(print_val), GINT_TO_POINTER(nmb));
    

    and then make your callback like this:

    static void print_val(GtkButton *button, gpointer nmb)
    {
        g_printf("%d\n", GPOINTER_TO_INT(nmb));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't get gtkmozembed to work: #include <gtk/gtk.h> #include <gdk/gdk.h> #include <gtkmozembed.h> #include <stdlib.h>
I have installed GCC-10.7-v2.pkg found at https://github.com/kennethreitz/osx-gcc-installer/downloads And I have removed Xcode completely following
GCC is a very well respected multi-language compiler (from what I've gathered). One thing
gcc I am just getting back into c programming and I am just practicing
GCC's recent support for atomic operations (as described here ) is great, and is
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,
gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,
GCC seem to think that I am trying to make a function call in
gcc 4.4.2 c89 I have a function that has to run (config_relays). It make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.