Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] Menu & Window Caption - special chars aren't displaying correctly
I have in caption and in menu special chars like "ľščťžýáíéúäň" - someone from this chars can't display correct in menu & window caption for exaple.: š,č,ž,ť...I don't have any idea how to correct this mistakes...
Which platform are you using?
Franzk last edited by
Make sure you use the correct encoding when writing these strings. Your source file has to be encoded correctly, as should you convert correctly to QStrings.
My advice on this would be to not use those characters in your code at all. In your basic application, you could use English (which has no special characters). Then, you use Qt Linguist to translate your application to the language you require. Of course, you do need to
make all user-visible strings translatable (good idea anyway)
install the translator in your QApplication (see the "documentation":http://doc.qt.nokia.com/4.7/linguist-programmers.html here)
build the .qm files from the .ts files
distribute the .qm files with your application, or build them into the application as a resource
This sounds like an encoding issue. Do the strings display correctly on a QLabel?
The same problem.
Then it should be an encoding problem.
I'd suggest you convert the source files into UTF-8. Qt Creator can do this, if you use it.
Then add to your .pro file:
CODECFORTR = UTF-8
CODECFORSRC = UTF-8
And add to your main method:
int main( int argc, char ** argv )
QApplication app(argc, argv);
// your code goes here
You could change UTF-8 to your ISO-8859-xxx version but then you might have problems with other characters, better make it UTF-8 if you set the codecs anyways.
Didn't help to me.
Can you create a small test program that demonstrates the behavior, then. Just a main method and a small class as GUI.
A screenshot of the test window would help too.
Guest last edited by
Saw a similar problem with the degree symbol ('\260' as a char). I recall the solution was related to which fonts were being used (Linux Font Server silently substituted some of them). Also hard-coding the needed symbol (hence the \260) was part of the solution.
[quote author="Peppy" date="1304452100"]
@Andre: That's not neccesary, it's just few strings (about 20)...[/quote]
That was not the point. The point is that it would probably save you from all the encoding issues (including those that may arise if some other dev opens up the file later on in some random editor, and doesn't realize that that is important).
I am back...so I have this KISS code:
int main(int argc, char *argv)
QApplication a(argc, argv);
QWidget* window = new QWidget(); window->setWindowTitle(QString("ľščťžýáíéäúňô")); window->resize(400,300); window->show(); QLabel* label = new QLabel(window); label->move(100,100); label->setText(QString("ľščťžýáíéäúňô")); label->show(); return a.exec();
Nothing more. And this is result: !http://i56.tinypic.com/p93qq.png(http://i56.tinypic.com/p93qq.png);!
I don't know what's need to change...System font is Tahoma which includes special chars, probably this is an issue on application side...
Try to follow Volker's suggestion that he posted 21 hours ago (the .pro file stuff and the encoding stuff in the main function).
I've tried, and this is result:
My platform is: Windows XP Pro SP2 SK MUI (EN/RU); Qt 4.7.1
[quote author="Peppy" date="1304530509"]I've tried, and this is result:[/quote]
You must actually change the encoding of your file. If you use Qt Creator go to the project pane, then to editor settings and change the default encoding to UTF-8.
For all your files that you have already: open them in Creator, go to menu Edit / Select Encoding... choose UTF-8 and click "save with encoding". This transforms all of your files to UTF-8 encoding.
If you know how to handle the tool, you can use something like recode too, of course. Just make sure Creator reloads the files, if they're open. Otherwise it overwrites the converted files. Better close all files before you do the conversion, quit Creator and open it afterwards.
Now it works! Great! Thank you...
But it's unbelievable that awful system, why there's no set up option to set up encoding? Now I have to change all files...
A few posts ago, it was only a mini project with 20 odd strings...
Yes, but in every file, I work with this strings! :D...
But what makes me sad is that, I make new project, I'll set up encoding (through settings) and it's another problem - also writes some strange captions. So the problem still going on...
I have been set up editors settings. I have been saving all files. I have been programming this files. And also it makes strange captions...I don't understand, maybe I am just so stupid, maybe it's my karma, or my Shauma, but it drives me mad...
You can set the default encoding in the preferences. It works like a charm. No troubles over here. I never had any problems.
But please keep in mind that changing the encoding afterwards can be error prone. You must make sure that all tools you use catch up the new settings, including external editors!
I don't use external editors, just Qt Creator.
So what I do:
I create a GUI project.
I write KISS code (as I showed on previous page)
Save with UTF-8
Build under Debugging
And It writes this unknown strings...
Sorry, I cannot help further. It works for me and many others. We do not have a crystal ball here, so we cannot see what are your settings are, whether the files are really saved with UTF-8, and if you did add the encoding stuff in the .pro and main method mentioned earlier....
But now, t gives much more stranger strings...much more different from this first problem...
And now? Do you expect us from this cool addition to help you any further? Some code, preferable a small, complete, compilable example in a ZIP, would get you out of that corner....
Your encodings are still messed up.
Please zip up the sources (and only the sources, please. no intermediary files like .o or moc_xxx and no executable).
And post a screenshot of your settings panes (preferences / text editor / behavior) and the project settings (projects / editor settings)
You must add the UTF-8 configs to your .pro and main method, as explained in "this comment":http://developer.qt.nokia.com/forums/viewreply/33472/
These steps are always required, when using UTF-8 encoded sources.
Really? Okay... I'll add it.
Yes, it works...great - problems are solved...
I am back: Another problem with encoding: Message Boxes...How to repair it?
giesbert last edited by
That was a question like: my computer crashes, what went wrong.
be more precise
give us code, exact locations etc.
[quote author="Peppy" date="1304760679"]I am back: Another problem with encoding: Message Boxes...How to repair it?[/quote]
You want to read: http://www.catb.org/~esr/faqs/smart-questions.html
And it write something like at the beginning of this topic (some special chars are not displayed correctly)...
Maybe Qt uses WIN32API function MessageBoxA(A as Ansi)(...); which should be deprecated, but it uses Ansi variant of MessageBox (my opinion)...
Yes, I've solved the problem and this is solution:
Do not work with output before set up the codecs (as it was shown before)...
Thank you guys, I think everything is solved...so let's mark as solved...
[quote author="Peppy" date="1304765139"]Thank you guys, I think everything is solved...so let's mark as solved...[/quote]
You can do this yourself:
Go to the very first post of this thread, click the edit link just below your avatar on the right and prepend "[Solved]" to the topic
hirakjyoti last edited by
Your code have successfully worked in my computer(Windows 7 & Qt 4.7.2)...