Trouble using DrawingArea for the first time



Hello.

I have been trying to follow the line-drawing example [1] on the on-line book in order to use the DrawingArea widget, but I get the following critical warning everytime the on_response_event() method gets called. The message indicates that the graphics context handler is null, but I am initializing it exactly like it is done in the example, i.e., in the on_realize() overriden method.

Gdk-CRITICAL **:
file gdkdraw.c: line 370 (gdk_draw_line): assertion `gc != NULL' failed

Here are some relevant snippets of code:

void KbDrawingArea::on_realize()
{
  Gtk::DrawingArea::on_realize();
  Glib::RefPtr<Gdk::Window> window = get_window();
  mGc = Gdk::GC::create(window);
  window->set_background(mBackground);
  window->clear();
  mGc->set_foreground(mLines);
}

bool KbDrawingArea::on_expose_event(GdkEventExpose* event)
{
  Glib::RefPtr<Gdk::Window> window = get_window();
  window->clear();
  window->draw_line(mGc, 1, 1, 100, 100);
  return true;
}

And this is how the DrawingArea widget is loaded with libglademm (actually, that is the only relevant difference between the example and my code):

  refGlade->get_widget_derived("draKb", mDraKb);

What am I missing?

[1] http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch14s03.html#id2635080

Thank you,

--
Ney André de Mello Zunino




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