Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt QMessageBox problem with Unicode (Tamil) and fromUTF8 function

Qt QMessageBox problem with Unicode (Tamil) and fromUTF8 function

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 6.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thefourtheye
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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/

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thefourtheye
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • A Offline
          A Offline
          absfrm
          wrote on last edited by
          #4

          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?

          If You Want You Can!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

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

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              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" ) );
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • A Offline
                A Offline
                absfrm
                wrote on last edited by
                #7

                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

                If You Want You Can!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved