Error in a simple GTK program


Windows 10 Home 64 bit, CodeBlocks 20.03. Program
#include <gtk/gtk.h>

static void destroy (GtkWidget*, gpointer);
static void color_changed (GtkColorButton*, GtkWidget*);

int main (int argc, char *argv[])
  GtkWidget *window, *button, *label, *hbox;

  GdkRGBA rgba;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Color Button");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);

  rgba.alpha = 0.0; = 0.0; = 0.0; = 0.0;
  button = gtk_color_button_new_with_rgba(&rgba);
  label = gtk_label_new ("Look at my color!");
  gtk_widget_override_color(label, GTK_STATE_NORMAL, &rgba);

  g_signal_connect (G_OBJECT (button), "color_set", G_CALLBACK (color_changed), (gpointer) label);

  hbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
  gtk_box_pack_start(GTK_BOX (hbox), button, FALSE , TRUE , 5);
  gtk_box_pack_start(GTK_BOX (hbox), label, FALSE , TRUE , 5);

  gtk_container_add (GTK_CONTAINER (window), hbox);

  gtk_widget_show_all (window);

  gtk_main ();
  return 0;

static void color_changed (GtkColorButton *button, GtkWidget *label)
  GdkRGBA rgba;
  gtk_color_chooser_get_rgba((GtkColorChooser*) button, &rgba);
  gtk_widget_override_color(label, GTK_STATE_NORMAL, &rgba);

static void destroy (GtkWidget *window,          gpointer data)
  gtk_main_quit ();
When I click on the button and start in terminal mode, an error appears "(cbGtkStudyWin.exe:1644): Gtk-CRITICAL **: gtk_box_reorder_child: assertion `GTK_IS_WIDGET (child)' failed". I looked through the entire code several times, but still did not understand, because of which an error occurs. Please help me figure it out.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]