简体   繁体   中英

Unicode and Text Controls Not Converting to UTF8 correctly

there. I am trying to pass a Text Field contents into a database call (mysql). When I look at the field that gets returned from Text->getvalue.(funct) call - I simply do not get the text that was entered into the field - via any of the UTF functions in WXWidgets. I have tried the following:

    wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().mb_str(wxConvUTF8);      
    //GooglyGook for whole thing
    wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().mb_str();   
    //NULL it fails completely
    wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().ToUTF8();  
    //More GOoblygook
    wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().utf8_str();
    //More Gooblygook
    message.Printf(_T("The title saved as wxCharBuffer =%s"),buffer.data());
    wxMessageBox(message,_("Rivendell"), wxICON_ERROR|wxOK);

The message box is how I am trying to display what is in the wxChar buffer, but I am running in debug so I can simply look at it during the run and confirm that it is incorrect. Please note that I have tried these wxChar buffer lines one at a time separately (not like they are listed here). Just wanted to show things I had tried.

What is the correct way to do this? The type of characters I am attempting to save in the db looks like:"check Todd 1 乞: 乞丐 qǐgài, 乞求 qǐqiú, 乞讨 qǐtǎo."

The gooblygook output looks like Chineese characters etc.. even in the English part of the field (Check Todd)...

Anyone who has an idea of how to do this please let me know. Thanks...

Tb

I appreciate the help provided, and after trying some things I found an answer. The correct way to do this seems to be the following: Put the TextCtrl field into a wxString using wx_str(). Then put the wxString into a wxCHarBuffer via toUTF8() function. Then use the data() function of the wxCHarBuffer to pass a char pointer.

Part of my problem stemmed from trying to display what was in those fields via Visual Studio Debugger, and/or wxMessage boxes - so sometimes my conversions were wrong (as noted by the previous poster). I was able to set the wxString (s) to Unicode characters and have it be handled correctly by the mysql call (ie Call would crash before). The chk_title variable returned seems to be correctly encoded into UTF8 and escaped. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM