webview blank white page when using unicode text Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

webview blank white page when using unicode text

Post by saifcoder »

Let's create sample WebView app.

Code: Select all

wxString MyText = wxT("<html><body>Hello</body></html>");
wxMemoryFSHandler::AddFile("MyFile.htm", MyText);
MyWebView->LoadURL("memory:MyFile.htm");
All work great, but when putting unicode text, the webview show blank white page!.

Code: Select all

wxString MyText = wxT("<html><body>أهلا</body></html>");
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder »

My build is Unicode, and i'm using unicode text in all widgets without any issue, except for webview.
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder »

In the official webview example it's show error.

Code: Select all

wxMemoryFSHandler::AddFile("page1.htm", wxT("<html><body>أهلا</body></html>"));
Attachments
webview_unicode.png
webview_unicode.png (54.71 KiB) Viewed 771 times
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: webview blank white page when using unicode text

Post by doublemax »

Code: Select all

wxString s( wxT("<html><meta charset=\"UTF-8\"><body>hey hey: أهلا</body></html>") );
wxCharBuffer cb = s.ToUTF8();
wxMemoryFSHandler::AddFile("page1.htm", cb, strlen(cb) );
Use the source, Luke!
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder »

Thank you so much doublemax for your help, so the default encoding it's not UTF-8! now I got it.

Ref: https://docs.wxwidgets.org/trunk/overview_string.html
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
Post Reply