Console and encoding

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
AlicVB
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Oct 28, 2007 8:22 am
Location: Jura, France
Contact:

Console and encoding

Post by AlicVB » Sat May 24, 2008 8:55 pm

Hi,

I have a problem with a small console app I wrote.
I detect a bug (in my app) when I pass args with characters like é,è,...
After a lot of test, I can reproduce the problem with a very small code :

Code: Select all

int main(int argc, char **argv)
{
    wxInitialize();
 
 
    wxCmdLineParser pp(argc,argv);
 
    pp.AddParam(_("File to open"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_PARAM_OPTIONAL);
 
    pp.SetSwitchChars (wxT("-"));
    if (pp.Parse()!=0) return false;
 
    if (pp.GetParamCount()!=0)
    {
        wxPuts(pp.GetParams(0));
        if (wxFileExists(pp.GetParam(0))) wxPuts("OK");
        return false;
    }
}
If the file passed as argument contains accents, The output show the path with a double strange characters in place of my é,è,... Of course, I never see the "OK" (wxwidgets don't find the file).

I think it's an encoding pb, but I can't find any solutions...
If someone can help me...

Thanks in advance !

AlicVB

Grrr
Earned some good credits
Earned some good credits
Posts: 126
Joined: Fri Apr 11, 2008 8:48 am
Location: Netherlands

Post by Grrr » Sun May 25, 2008 7:37 pm

Try calling wxLocale::Init() before creating the wxCmdLineParser.

AlicVB
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Oct 28, 2007 8:22 am
Location: Jura, France
Contact:

Post by AlicVB » Mon May 26, 2008 6:49 pm

I'm afraid this is not the pb : I try wxLocale::Init() with parameters, without, ...

I can add that this code :

Code: Select all

int main(int argc, char **argv)
{
    wxInitialize();
    if (wxFileExists(_T("/home/myhome/été/truc.txt"))) wxPuts(_T("OK"));
    return 1;
}
Doesn't show the 'OK' (and the file pointed exists !)
Any thought ?

Thanks
AlicVB

Grrr
Earned some good credits
Earned some good credits
Posts: 126
Joined: Fri Apr 11, 2008 8:48 am
Location: Netherlands

Post by Grrr » Tue May 27, 2008 7:06 am

What platform are you using (Windows, Mac, Linux). Do you use the Unicode build of wxWidgets? Do you use the Unicode build of your application?

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Tue May 27, 2008 9:49 am

Under windows try to put absolute path like this:

"C:\\myfolder\\myfile.txt"
OS: Windows XP
Compiler: Mingw-5.1.3 in Code::Blocks
wxWidgets: 2.8.7 unicode release dll monolithic

AlicVB
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Oct 28, 2007 8:22 am
Location: Jura, France
Contact:

Post by AlicVB » Tue May 27, 2008 11:31 am

First, thanks for your answers.
Then, I'm under Linux (Xubuntu 8.04) and I develop with Code::Blocks nightly build.
I have an Unicode version of wxWidgets libs (the ubuntu official one).
But I don't know what how to specify that I want an unicode build of my application.

Thanks
AlicVB

PS : I'll try to edit my signature and specify my OS.

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Tue May 27, 2008 1:38 pm

First of all, i think it depends on your buil of wxwidgets.
When you compiled it you must had specified this option.

Anyway in compiler option you have to define
wxUSE_UNICODE
OS: Windows XP
Compiler: Mingw-5.1.3 in Code::Blocks
wxWidgets: 2.8.7 unicode release dll monolithic

Post Reply