Qt QMessageBox problem with Unicode (Tamil) and fromUTF8 function



  • Hi,

    I am trying to create a message box with a unicode string in it. It doesnt work. I am seeing only question marks in the message box. This is what I have tried.

    QMessageBox::information(NULL, "First", QString::fromUtf8("சக்தி"));

    But this works

    [code]QMessageBox::information(NULL, "First", QApplication::translate("QDlgLoginForm", "\340\256\232\340\256\225\340\257\215\340\256\244\340\256\277", 0, QApplication::UnicodeUTF8));[/code]

    I set the unicode string as text in a button and copied these numbers from the auto-generated ui header file.

    Is there a function to convert a unicode string to those weird numbers? Any workarounds would also make me happy... Thanks



  • For your first approach you must make sure that your source code file is saved in Unicode UTF-8. If you ensure that, it works - we do it in our project all the time.

    To change default encoding, go to Settings / Text Editor / Tab Behavior, there you find the encoding settings. Be aware that this does not change the encoding for existing files, you will have to do that using external tools like an editor using save-as or "recode":http://directory.fsf.org/project/recode/



  • Hi Volker,

    Thanks a bunch... :) That exactly solved my problem..

    [quote author="Volker" date="1316346238"]For your first approach you must make sure that your source code file is saved in Unicode UTF-8. If you ensure that, it works - we do it in our project all the time.

    To change default encoding, go to Settings / Text Editor / Tab Behavior, there you find the encoding settings. Be aware that this does not change the encoding for existing files, you will have to do that using external tools like an editor using save-as or "recode":http://directory.fsf.org/project/recode/[/quote]



  • Hi
    i have this error too.
    and i exec your help , but its not true for me!

    this is my source code. (my .....cpp was utf-8 saved by external editor)
    !http://up8.iranblog.com/images/hx0q5xk0nleszpt7tlh.png(First)!

    and this is my output.
    !http://up8.iranblog.com/images/gdkiroa9754002cbsrc.png(Sec)!

    what's the problem?



  • There is a simple thing: don't use utf8 in source files. use translation files for those things.



  • Either set your text this way:

    @
    msgBox.setText(QString::fromUtf8("your text"));
    @

    or add to your .pro file

    @
    CODECFORTR = UTF-8
    CODECFORSRC = UTF-8
    @

    and this to your main method right after the instantiation of the QApplication object:

    @
    QTextCodec::setCodecForCStrings( QTextCodec::codecForName( "UTF-8" ) );
    QTextCodec::setCodecForTr( QTextCodec::codecForName( "UTF-8" ) );
    @



  • Hi Gerolf
    My application is in one language(just utf-8 unicode). thanks,your right;

    And hi Volker. @msgBox.setText(QString::fromUtf8("your text"));@
    this is so useful code for me. thanks a lot

    best regards


Log in to reply
 

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