Reputation: 13
I'm struggling trying to set a wchar_t array in my Gtk/ c++ application. For some unknown reason the Gtk methods do not have a overloaded form which support wchar_t arrays but only gchar ones.
I've read couple articles which made me wonder that it may be a variable-width encoding concern, which is set in regular UTF-8. I'm trying to do something like:
std::wstring propertiesText;
/*
String Manipulation...
*/
gtk_label_set_text( (GtkLabel*)_propertiesLabel, propertiesText.c_str() );
And as I said said the compiler is complaining that the wchar_t is not supported by this method.
If you can clear my issue in any form or even explain something about these variable-width encoding/ wide-characters relation.
Upvotes: 0
Views: 1079
Reputation: 1
GTK is built above Glib. And Glib has deeply supposed that all strings are UTF-8 encoded. Also wchar_t is not very portable (on some compilers, it might be 16 bits, on others, it could be 32 bits). So you should avoid using wchar_t
or std::wstring
in your code. BTW, you could be interested in Gtkmm if you are coding in C++ (then consider using Glib::ustring-s).
If you absolutely need to use std::wstring
for some reason you have to make the (perhaps costly) conversions to and from Glib UTF-8 encoded string explicitly by hand.
Upvotes: 3