invalid conversion from 'const char*' to 'wxChar'

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
New_wx_User
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Sep 17, 2009 12:43 pm

invalid conversion from 'const char*' to 'wxChar'

Post by New_wx_User »

Hi,

I'm currently working on a Program for my Bachelor thesis and it uses wxWidgets-2.8.10 (I have a Mac). When I try to compile the files, I'm getting this error message:

g++ -c -O3 `wx-config --cxxflags` -c -o GUI.o GUI.cc
GUI.cc: In member function ‘Case* GUI::add_case()’:
GUI.cc:41: error: invalid conversion from ‘const char*’ to ‘wxChar’
GUI.cc:41: error: initializing argument 1 of ‘wxString::wxString(wxChar, size_t)’
GUI.cc:42: error: no matching function for call to ‘Case::create(int&, wxChar**&)’
Case.h:47: note: candidates are: void Case::create(int, char**)
GUI.cc:45: error: invalid conversion from ‘const char*’ to ‘wxChar’
GUI.cc:45: error: initializing argument 1 of ‘wxString::wxString(wxChar, size_t)’
make: *** [GUI.o] Error 1

the code from GUI.cc is here:

#include "GUI.h"
#include "Case.h"
#include "Color_Key.h"
#include "wx/bitmap.h"

IMPLEMENT_APP(GUI)

wxApp * theApp = &wxGetApp();

bool GUI::OnInit()
{
add_case();

return true;
}

Case * GUI::add_case()
{
int x, y;

Case * c = new Case(this, "Cancer Grid", wxPoint(-1,-1), wxSize(600,400));
c->create(argc, argv);
c->GetPosition(&x, &y);

Color_Key * colorkey = new Color_Key(c, "Key", wxPoint(x, y+420));
colorkey->render();
colorkey->Show();
SetTopWindow(colorkey);

c->set_palette(colorkey->palette());
c->Show();
SetTopWindow(c);
return c;
}

void GUI::case_holder_duplicate(const Case * c)
{
Case * c2 = add_case();
c->clone(c2);
}


I don't know why it can't convert char to wxChar, so I it would be great if someone can help me.

Thanks!
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

Hi,

you are compiling in unicode mode. This requires wxT() macros when using char*.

Code: Select all


#include "GUI.h"
#include "Case.h"
#include "Color_Key.h"
#include "wx/bitmap.h"

IMPLEMENT_APP(GUI)

wxApp * theApp = &wxGetApp();

bool GUI::OnInit()
{
add_case();

return true;
}

Case * GUI::add_case()
{
int x, y;

Case * c = new Case(this, wxT("Cancer Grid"), wxPoint(-1,-1), wxSize(600,400));
c->create(argc, argv);
c->GetPosition(&x, &y);

Color_Key * colorkey = new Color_Key(c, wxT("Key"), wxPoint(x, y+420));
colorkey->render();
colorkey->Show();
SetTopWindow(colorkey);

c->set_palette(colorkey->palette());
c->Show();
SetTopWindow(c);
return c;
}

void GUI::case_holder_duplicate(const Case * c)
{
Case * c2 = add_case();
c->clone(c2);
} 


I have inserted the marcos in your code (see above).
Please read this http://wiki.wxwidgets.org/WxString. It might help you a bit.

Best regards

Orbitcowboy
OS: Ubuntu 9.04 (32/64-Bit), Debian Lenny (32-Bit)
Compiler: gcc/g++-4.3.3 , gcc/g++-4.4.0
wxWidgets: 2.8.10,2.9.0
New_wx_User
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Sep 17, 2009 12:43 pm

Post by New_wx_User »

Thank you for the fast reply, but is there another way to solve this problem, cause it's to much to change in the program code (there are a lot of files to changed!).
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

New_wx_User wrote:Thank you for the fast reply, but is there another way to solve this problem, cause it's to much to change in the program code (there are a lot of files to changed!).
Yes, there is another way. Compile your application in ansi and NOT in uncicode mode using the wx-config --unicode=no. This requires maybe that you have to first rebuild the wxWidgets library in ansi mode.
OS: Ubuntu 9.04 (32/64-Bit), Debian Lenny (32-Bit)
Compiler: gcc/g++-4.3.3 , gcc/g++-4.4.0
wxWidgets: 2.8.10,2.9.0
New_wx_User
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Sep 17, 2009 12:43 pm

Post by New_wx_User »

You're right, I have to rebuild it in ansi mode, but I don't know how I should do that. Sorry, if I'm asking stupid Questions...
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

New_wx_User wrote:You're right, I have to rebuild it in ansi mode, but I don't know how I should do that. Sorry, if I'm asking stupid Questions...
No problem (in linux :-) ... others i don't know):

Download the wxWidgets sources from:

http://www.wxwidgets.org/downloads/

then, type the following commands in the linux shell:

tar -xpvzf wxWidgets*.tar.gz
cd wxWidgets/
mkdir ansi_build
cd ansi_build
../configure
make
make install

The ansi build is default (at current stable version 2.8.10).

Hope it helps.

Best regards

Orbitcowboy
OS: Ubuntu 9.04 (32/64-Bit), Debian Lenny (32-Bit)
Compiler: gcc/g++-4.3.3 , gcc/g++-4.4.0
wxWidgets: 2.8.10,2.9.0
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Another potentially better solution : use wxWidgets 2.9 (3.0 development version). This version allows implicit conversion from char*, without sacrificing unicode features
"Keyboard not detected. Press F1 to continue"
-- Windows
New_wx_User
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Sep 17, 2009 12:43 pm

Post by New_wx_User »

okay, I rebuild in ansi-mode, but now I can't use wx-config. There's only wx-config.in int the directory and when I try to use it, the following message occurs:

maggy:wxMac-2.8.10 praktikant$ ./wx-config.in --libs

Warning: No config found to match: ./wx-config.in --libs
in @libdir@/wx/config
If you require this configuration, please install the desired
library build. If this is part of an automated configuration
test and no other errors occur, you may safely ignore it.
You may use wx-config --list to see all configs available in
the default prefix.
New_wx_User
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Sep 17, 2009 12:43 pm

Post by New_wx_User »

Okay everything is solved, thanks to everybody!
Post Reply