0

Hi I'm trying to show an error mesaage using a dialogbox. However when I run the code I get segmentation fault.

Here's the function:

void ShowErrorMessage(string message)
{
  Gtk::MessageDialog dialog(message,true,Gtk::MESSAGE_ERROR,Gtk::BUTTONS_CLOSE,true);
  dialog.run();
}

I try to open a file, if the file can not be open I wanna show this error box, however i keep running into segmentation fault.

bk1e
  • 23,871
  • 6
  • 54
  • 65
ace
  • 2,141
  • 7
  • 29
  • 39
  • There's really not enough context here to figure it out. What is the stack trace when you get the segfault? – jonner Jan 29 '10 at 03:47
  • Are you using chars other than the ASCII ones in `message`? If this is the case, ensure to encode them in UTF8. – ntd Jan 29 '10 at 16:17
  • hmm..I guess I can try that...how do i encode them in UTF8? – ace Jan 29 '10 at 20:40
  • http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-ustring.html.en If this is the problem, you should basically use Glib::locale_to_utf8(). – ntd Jan 30 '10 at 16:05
  • Thanks that didn't solve the problem, I guess it's a problem with the dialogbox not having a parent window 'cuz i'm calling it before my main window shows. What do you think ? – ace Jan 30 '10 at 16:40
  • You can also show a dialog without any parent window, there is no dark magic involved. My guess is your problem is of totally different nature: providing a minimal test case exposing the problem would be much more helpful. – ntd Jan 31 '10 at 20:13

2 Answers2

0

Do you have to call new on the dialog or is that a static class? See here for the document on this, which is leading me to think that's why your code segfaults...

Hope this helps, Best regards, Tom.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
0

maybe you did not added this line at the begining?

Gtk::Main_kit(argc, argv);
aliva
  • 5,450
  • 1
  • 33
  • 44