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: 70
Joined: Thu Nov 16, 2017 9:32 pm

webview blank white page when using unicode text

Post by saifcoder » Sun Dec 29, 2019 7:48 pm

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.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder » Sun Dec 29, 2019 7:55 pm

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.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder » Sun Dec 29, 2019 8:36 pm

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 213 times
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
doublemax
Moderator
Moderator
Posts: 14639
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: webview blank white page when using unicode text

Post by doublemax » Sun Dec 29, 2019 9:08 pm

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: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: webview blank white page when using unicode text

Post by saifcoder » Sun Dec 29, 2019 9:29 pm

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.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

Post Reply