Page 1 of 1

You forgot to call g_type_init()

Posted: Tue Dec 25, 2012 9:22 am
by 08S011003
本人刚接触wxWidgets,运行一个简单的程序,

Code: Select all

#include <wx/wx.h>

/**
   A frame that contains a text control.
*/
class TextFrame : public wxFrame
{
public:
   /**
      Constructs the text control.
   */
   TextFrame();
private:
   wxTextCtrl* text;
};

/**
   An application that shows a frame with a text control.
*/
class TextApp : public wxApp
{
public:
   /**
      Constructs the frame.
   */
   TextApp();
   /**
      Shows the frame.
      @return true
   */
   virtual bool OnInit();
private:
   TextFrame* frame;
};

DECLARE_APP(TextApp)

IMPLEMENT_APP(TextApp)

TextFrame::TextFrame() 
   : wxFrame(NULL, -1, "TextFrame")
{
   text = new wxTextCtrl(this, -1, "Type some text here!",
      wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
}

TextApp::TextApp()
{
   frame = new TextFrame();
}

bool TextApp::OnInit()
{
   frame->Show(true);
   return true;
}
出现如下错误,

(process:4096): GLib-GObject-CRITICAL **: gtype.c:2710: You forgot to call g_type_init()

(process:4096): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed

(process:4096): Gdk-CRITICAL **: IA__gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed
./src/unix/displayx11.cpp(425): assert "dpy" failed in wxClientDisplayRect(): can't be called before initializing the GUI

(process:4096): GLib-GObject-CRITICAL **: gtype.c:2710: You forgot to call g_type_init()

请给予指导。

Re: You forgot to call g_type_init()

Posted: Wed Dec 26, 2012 8:39 am
by kipade

Re: You forgot to call g_type_init()

Posted: Wed Apr 24, 2013 2:07 am
by ccnyou
检查你代码中用到的全局变量