GTK获取滑块值

时间:2014-02-18 11:10:18

标签: gtk gtk3

如何在GTK中获取滑块值?

#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>

GtkWidget *speed_sld,*speed_label;

static void transmit (GtkWidget *widget,gint *data)
{
  float val = gtk_scale_get_digits(data);
  g_print("Val is %f \n",val);
}

int main (int argc, char *argv[])
{
    GtkBuilder *builder;
    GtkWidget *window;


    gtk_init (&argc, &argv);

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "./ECU.glade", NULL);

    window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    //g_signal_connect (window, "destroy", G_CALLBACK (on_window_destroy), NULL);

    speed_sld = GTK_WIDGET (gtk_builder_get_object (builder, "scale1"));
    speed_label = GTK_WIDGET (gtk_builder_get_object (builder, "label1"));

    g_signal_connect (speed_sld, "value-changed", G_CALLBACK (transmit), NULL);

    gtk_widget_show_all (window);
    gtk_main ();
}

如何在发送功能中打印滑块值?我尝试打印数据,*数据等如何获取函数内的值

1 个答案:

答案 0 :(得分:4)

data是指向g_signal_connect中提供的任何数据的指针(你提供了NULL),所以没有意义。

我猜你看到GtkScale文档后感到困惑:记住你还需要查看父窗口小部件API,在这种情况下是GtkRange。这应该有效:

static void transmit (GtkRange *range, gpointer data)
{
  g_print ("current value is %f\n", gtk_range_get_value (range));
}