In D, how to pass an empty string? (to gtkD)
Asked Answered
U

3

5

Using D1 with phobos

I have a text entry field, instance of gtk.Entry.Entry,

calling setText("") raises a run time error

Gtk-CRITICAL **: gtk_entry_set_text: assertion `text != NULL' failed

Why? It seems to be a problem with D, I tried this:

string empty = "";
assert (empty != null);
my_entry.setText(empty)

The program terminated as the assertion failed.

How can I work around this?

Urrutia answered 31/5, 2009 at 5:14 Comment(0)
D
5

I don't think D really differentiates between "empty string" and "null string". A cheap workaround would be setText(" ").

[edit] Nevermind that. It's a bug in gtkD. in trunk/src/glib/Str.d (thanks wm4 for finding it), change line 147 to return ""; (remove the .dup).

Douglasdouglashome answered 31/5, 2009 at 5:33 Comment(0)
C
3

You should write assert(empty !is null) instead of assert(empty != null)

Confirmed answered 31/5, 2009 at 23:19 Comment(0)
U
1

I used "\0" and it seemed to work,

I don't know if any invisible character got into the text field, but this is based on the assumption that an empty string in C is just \0

Urrutia answered 31/5, 2009 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.