String handling in IRRLICHT

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
PixelBender
Posts: 7
Joined: Thu Oct 20, 2016 8:30 am

String handling in IRRLICHT

Post by PixelBender »

Hi all,

I have problems working with strings in irrlicht.
For instance I have a string like “model.3ds” in an XML file und want to use it as text label on a GUI element.
How can the content be transported from the xml file to the GUI label?

XML handling:

Code: Select all

            case io::EXN_ELEMENT:
            {
                if (core::stringw("startUpModel") == xml->getNodeName())
                {
                    StartUpModelFile = xml->getAttributeValue(L"file");
                }
 
In the case above StartUpModelFile hast the type

Code: Select all

 core::stringc 
while the

Code: Select all

setText() 
method expects

Code: Select all

const wchar_t*
 
When I have to enter a string hardcoded I would write: setText(L”blabla”);

But how am I expected to use the variable StartUpModelFile?

Code: Select all

setText(StartUpModelFile)
doesn’t work

Code: Select all

setText(StartUpModelFile.c_str())
neither.
Nor

Code: Select all

 setText(L(StartUpModelFile))
 
Any help appreciated

Greetings
Markus
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: String handling in IRRLICHT

Post by CuteAlien »

You can probaly do setText( irr::core::stringw(StartUpModelFile).c_str() );
Which is fine as long as you have only ansi strings (no international characters). If you have unicode or multibyte strings then you have to convert them (Irrlicht trunk has some functions for that).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
PixelBender
Posts: 7
Joined: Thu Oct 20, 2016 8:30 am

Re: String handling in IRRLICHT

Post by PixelBender »

Hi CuteAlien,

that was exactly, what I needed.
Works like a charm :D

Thank you for your help.

From my non expert point of view those many different string types in c++ are a plaque.
I have problems to understand why in a small area like the irrlicht API it wasn't possible to concentrate on one string type
for all the function parameters instead of making endless conversions necessary.

Greetings
Markus
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: String handling in IRRLICHT

Post by CuteAlien »

The problem is you still get all kind of different string types from all kind of places. C++ has to handle all those - it didn't create them in the first place :-)

If you know you have wide-string in your xml you can use getAttributeAsStringW instead of getAttributeValue.
Irrlicht used some places stringc (like logging and for labels). Which is a little unfortunate, but not easy to change without breaking all applications using Irrlicht.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply