Char is not large enough

Pages: 12
Sorry I was looking at the wrong thing. So your saying I should change:



is that correct?

Last edited on
Just change all the char parameters for that function to wchar_t.
Maybe I should have shown you this before but to be honest I am not sure what the second createBtn does or how you can even have two methods with the same name:


Last edited on
Are you changing the corresponding KeyboardWidget.h file?
Remember, like Ganado points out, functions will have declarations and definitions. You can't just change a data type in the definition, you must also change the corresponding declaration in the header file to match.
@Ganado No... sorry I forgot I needed to change the header files as well.

So would the proper way to declare:



Last edited on
Those are calls, not declarations.

static_cast<wchar_t>(0x0147) and wchar_t(0x0147) are equivalent snippets.
@helios Ah, I see. Okay well I made the changes and it builds fine but unfortunately* my keyboard widget is still displaying a G where it should be Ň. So maybe there is some other reason for that; other than the size of char that is.
Last edited on
Can you post the relevant code that is compiling but still displaying a G?

Also which version of Qt are you using? Qt5?
Sorry I have taken so long to reply. I have been on vacation.

@Ganado I believe most of the code has already been posted but I will re-post:

Note: KeyboardWidget() only shows constructor and a single block of QHboxLayout for brevity:

Last edited on
I changed the above methods in the following ways:

For some reason that pesky Ň is still showing up as a G..
Last edited on
This is still erroneous
createBtn(row1, 2, '5', ')', '5', static_cast<char>(0xDF), static_cast<char>(0x0147))
Specifically: static_cast<char>(0x0147)
You're still trying to cast a value of 0x0147 (327) into a char (0-255, 0x00-0xFF), which is not possible. (Edit: I mean, not possible without loss of information)

It doesn't look like you're using your
createBtn(QHBoxLayout*, int, bool, int, const char*, bool) function.

I believe most of the code has already been posted but I will re-post:
The reason I asked for the code again is that it should have changed.
Last edited on
Casting 0x0147 into char drops all but the least meaningful 8 bits, i.e. gives 0x47. The 0x47 is G.
The code in my second to last post has been changed in the same way as the code in my last post. I changed the all of the 'char' parameters to be 'wchar_t' and then deleted all of the static_cast<char> references. Everything compiled but I am still getting a 'G' instead of an 'Ň'. The createBtn(QHBoxLayout*, int, bool, int, const char*, bool) is being used for a few different things. Maybe it will help if I post the whole keyboard:

Last edited on
In c2s(): QLatin1Char() accepts a char, so you're still truncating the value.
To construct a QString from a wchar_t do this:
1
2
3
QString to_QString(wchar_t c){
    return QString::fromWCharArray(&c, 1);
}
Yep! I saw that not 20 seconds before Genado told me to come here and look at what you posted! I am going to study this method a bit (not sure I know how it works) but I implemented it and it works for the QString conversion. Hey, thanks a bunch for sticking with me here!!! Finally got that 'Ň'!
Topic archived. No new replies allowed.
Pages: 12