[SOLVED] Encoding troubles



  • [SOLVED]

    Hi,

    i have troubles with encoding. In my app there is a QGraphicsView, and when i click on one of menu buttons it creates a new QGraphicsTextItem inside of QGraphicsView. A problem is that some czech characters don't show properly, there are crazy symbols instead of the right ones .. but another part off app is, when i rightclick created QGraphicsTextItem and choose Edit from shown context menu, my app shows text editor where i can edit a text shown in my QGraphicsTextItem and when i use czech characters like ěščřžýáíé, everything works ... My problem is that i need to have some text including czech characters when QGraphicsTextItem is initialized and I cannot find a solution..


  • Moderators

    How do you initialize the default text in your source code? Is the source file encoded in UTF-8?



  • QString tip="Text můžete upravit pomocí kontextového menu položky.";
    text = new myQGraphicsTextItem(tip);

    every file in my project is in UTF-8, in qt this text looks like above, but when i press ctrl+R and run app and click to create a new QGraphicsTextItem, then it shows crazy characters instead of ů.ž,é and ž in the last word.
    I had same problem when i initialized it as text = new myQGraphicsTextItem("Text můžete upravit pomocí kontextového menu položky."); .. tried to set text into a QString, cuz QString should contain UTF-8 text, but it makes no difference for me ..


  • Moderators

    @
    QString tip=QStringLiteral(“Text můžete upravit pomocí kontextového menu položky.”);
    // or
    QString tip(trUtf8(“Text můžete upravit pomocí kontextového menu položky.”));
    @

    I'm not sure any of those would help, source text encoding can be a PITA. I think there are also some compiler flags that you can use to force it to use an encoding.



  • the second one

    @ QString tip(trUtf8(“Text můžete upravit pomocí kontextového menu položky.”));@

    works well for me, thanks a lot :)



  • Hi,
    Maybe add this:
    @CODECFORSRC = UTF-8@
    to your pro file. That will setup the default way of coding the source files
    also your QString init is a bit C, not C++. Use the constructors available to create a QString(....); not QString = ....


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.