Search code examples
cgtkgobject

g_signal delays (C, GTK+)


I've got a little GTK-Application with two buttons (A, B) and a drawing area (C). When I click on A, C's size should be recalculated and set with gtk_widget_set_size_request(). This will cause an expose-event, whose handler will calculate some data. Further, the click on A will emit a clicked signal at B, whose handler needs the data calculated by C's expose-event.

In fact everything works fine, but the expose-event delays somehow, and the clicked handler is called before and the data (you may guess it) is missing.

a_handler() {
   new_size = calculate_size();
   gtk_widget_set_size_request(C, new_size); //Will cause expose-event
   g_signal_emit_by_name(B, "clicked");
}

b_handler() {
   calculate_something(data); //Error
}

c_handler() {
   draw_something();
   data = calcluate_data();
}

What can I do?


Solution

  • The ugly fix is typically to add calls to gtk_main_iteration(), for instance between the call to gtk_widget_set_size_request() and the signal-emission.