Hi,
I have a problem initializing a wxString...
wxUSE_UNICODE=0
wxUSE_WCHAR_T=1
wxString str( "Hello" );
==> cannot convert parameter 1 from 'const char [6]' to 'int'
wxString str = "Hello";
==> cannot convert from 'const char [6]' to 'wxString'
std::string s("Hello");
wxString str = s.c_str();
==> cannot convert from 'const char *' to 'wxString'
But when I use:
wxString str = wxT("Hello");
==> Everything works fine...
When I look at the preprocessed file (.i), I see that wxChar got typedef'ed to char, I see wxString has a constructor const wxChar * psz... So I am really puzzled here why this is happening!
Hope that someone can help me
Greetz,
Steven
[wxString] problem when initializing Topic is solved
[wxString] problem when initializing
wxWidgets: SVN/trunk
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be
Maybe you should try simple type casting? I had a similar problem and now it works fine.
Hope this will work Regards -
sitsuj
Code: Select all
wxString login_value = (wxString)"your login";
sitsuj
-
- Knows some wx things
- Posts: 26
- Joined: Tue Nov 14, 2006 1:51 pm
- Location: Duesseldorf, Germany
This will again only work if the character type is only one byte wide. In general, you're safest when you mark all literal strings with wxT(), since this works fine in both Unicode and ANSI modes.
More precisely:
A narrow character string in C++ is represented by the text within quotation marks. A wide character string is represented likely, but with an L prefixing the first quotation mark. The wxT macro makes sure that there is an L in Unicode mode, and that there isn't in ANSI mode.
More precisely:
A narrow character string in C++ is represented by the text within quotation marks. A wide character string is represented likely, but with an L prefixing the first quotation mark. The wxT macro makes sure that there is an L in Unicode mode, and that there isn't in ANSI mode.
Code: Select all
char const* ansi = "Hello, World"; // ANSI
wchar_t const* unicode = L"Hello, World"; // Unicode
wxChar const* whatever = wxT("Hello, World"); // Expands to what's appropriate
Ok,
I don't know what's wrong. Let's just blame Microsoft. I did a complete rebuild of the project, and now it seems that wxChar is being converted to wchar_t in the preprocessed file...
So I found the solution now (provide a wxConv).
Greetz & thx!
I don't know what's wrong. Let's just blame Microsoft. I did a complete rebuild of the project, and now it seems that wxChar is being converted to wchar_t in the preprocessed file...
So I found the solution now (provide a wxConv).
Greetz & thx!
wxWidgets: SVN/trunk
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be