Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2007
Problems with UTF-8 source files


Message 1 in thread

Hi,

First of all I would like to thank the Trolls for Qt. I discovered it some 
months ago, I got the German translation of the official book for Qt 4 by 
Jasmin Blanchette and Mark Summerfiled for Christmas and now I think I will 
never use Borland again to write my applications ;-) Keep it up!

Well, and here is my problem:
I've got some trouble using UTF-8 source files in my Qt project (I'm working 
with Qt 4.2.2 on Kubuntu 6.10).
I write my applications directly in German, and I don't want to write them in 
English and then translate them. So I use the umlauts directly in the source 
files, and everything works fine as long as I use ISO-8859-1 as charset. But 
as I like the idea of one charset for everything I'd like to use UTF-8 in my 
source files (edited with Kate or QDevelop, that doesn't seem to matter) 
which I thought should not be too difficult because Qt supports so much 
charsets.
To have the umlauts displayed correctly, I call
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"))
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
at the beginning of my program (setCodecForTr is enough but to be shure I also 
set the other charsets) which works fine. But the problem appears as soon as 
I use lupdate to create a translation file: lupdate does not use UTF-8 as 
charset but ISO-8859-1 or something similar, and so the umlats are only some 
strange characters in linguist.
I found a possibility to change that with the following options in my pro 
file:

CODECFORTR      = UTF-8
CODECFORSRC     = UTF-8

(by the way, why aren't they mentioned at 
http://doc.trolltech.com/4.2/qmake-variable-reference.html but only here: 
http://doc.trolltech.com/4.2/linguist-manager.html ?)

Using these options, linguist shows the umlauts correct. But even if the 
translation is loaded by my application, the strings with the umlauts are not 
translated (whereas the strings without umlauts are). It seems to me that tr 
doesn't find the translated string if it contains UTF-8 characters. What can 
I do to have the translation working?
I created a little application demonstrating the problem and uploaded it to 
http://home.arcor.de/mathe.spiele/upload/charset2.tar.gz.

Thanks for your help,
Ralf

--
 [ signature omitted ] 

Message 2 in thread

Cannot help you, but:

> I write my applications directly in German, and I don't want to write them in 
> English and then translate them.

Perhaps you should reconsider. I usually 'translate' my english text 
with the linguist even if I write them in my code in english. Sometimes 
I even use some short 'placeholders' like 'filenotfound' and 
decide much later, what the final text will be. I can say this proved very 
advantageous more than once.
   
Guido


--
 [ signature omitted ] 

Message 3 in thread

On 01.02.07 21:59:59, Guido Seifert wrote:
> > I write my applications directly in German, and I don't want to write them in 
> > English and then translate them.
> 
> Perhaps you should reconsider. I usually 'translate' my english text 
> with the linguist even if I write them in my code in english. Sometimes 
> I even use some short 'placeholders' like 'filenotfound' and 
> decide much later, what the final text will be. I can say this proved very 
> advantageous more than once.

What happens if somebody with a locale that you don't provide translation
for uses your app? Is the english text still shown or your
abbreviations?

I do agree however that one should use english in the sources...

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

> What happens if somebody with a locale that you don't provide translation
> for uses your app? Is the english text still shown or your
> abbreviations?

Dammit, now I configured my mutt that I can send directly to the list, 
but it still happens that I use the wrong command and answer directly to 
the sender.
 

English is the default and is used when an unknown locale is selected or
a necessary .qm file is not found. Ok, the english .qm should not be 
missing. This would be the only way that it could happen that you see 
the abbreviations. Maybe I will integrate the english .qm file with the 
resource system into the binary. Not sure about that, yet. 

Guido


--
 [ signature omitted ] 

Message 5 in thread

"Ralf Jung" <ralfjung-e@xxxxxx> wrote in message 
news:200702012142.50265.ralfjung-e@xxxxxxxxx
> Hi,
>
> First of all I would like to thank the Trolls for Qt. I discovered it some
> months ago, I got the German translation of the official book for Qt 4 by
> Jasmin Blanchette and Mark Summerfiled for Christmas and now I think I 
> will
> never use Borland again to write my applications ;-) Keep it up!
>
> Well, and here is my problem:
> I've got some trouble using UTF-8 source files in my Qt project (I'm 
> working
> with Qt 4.2.2 on Kubuntu 6.10).
> I write my applications directly in German, and I don't want to write them 
> in
> English and then translate them. So I use the umlauts directly in the 
> source
> files, and everything works fine as long as I use ISO-8859-1 as charset. 
> But
> as I like the idea of one charset for everything I'd like to use UTF-8 in 
> my
> source files (edited with Kate or QDevelop, that doesn't seem to matter)
> which I thought should not be too difficult because Qt supports so much
> charsets.
> To have the umlauts displayed correctly, I call
> QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"))
> QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
> QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
> at the beginning of my program (setCodecForTr is enough but to be shure I 
> also
> set the other charsets) which works fine. But the problem appears as soon 
> as
> I use lupdate to create a translation file: lupdate does not use UTF-8 as
> charset but ISO-8859-1 or something similar, and so the umlats are only 
> some
> strange characters in linguist.
> I found a possibility to change that with the following options in my pro
> file:
>
> CODECFORTR      = UTF-8
> CODECFORSRC     = UTF-8
>
> (by the way, why aren't they mentioned at
> http://doc.trolltech.com/4.2/qmake-variable-reference.html but only here:
> http://doc.trolltech.com/4.2/linguist-manager.html ?)
>
> Using these options, linguist shows the umlauts correct. But even if the
> translation is loaded by my application, the strings with the umlauts are 
> not
> translated (whereas the strings without umlauts are). It seems to me that 
> tr
> doesn't find the translated string if it contains UTF-8 characters. What 
> can
> I do to have the translation working?
> I created a little application demonstrating the problem and uploaded it 
> to
> http://home.arcor.de/mathe.spiele/upload/charset2.tar.gz.

Does it work if you call trUtf8?

http://doc.trolltech.com/4.2/qobject.html#trUtf8

Also see the warning in the documentation; if your source code is compiled 
by someone not running in a UTF8 locale, then your german umlaut characters 
might get you interesting results.

Volker



--
 [ signature omitted ] 

Message 6 in thread

Is it possible to left-align the icons in a QListWidget?  I've set the text
alignment in each of the items, but don't see any way to do the same with the
icons. The problem is that the position of the icon is based on the length of
the text it's centered over. So with texts of different lengths, I'm ending up
with a column of icons that are haphazardly aligned.

If there's no way to set this directly, is there a convenient workaround?


 
____________________________________________________________________________________
Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367

--
 [ signature omitted ] 

Message 7 in thread

I too was wondering about this.  Last night I started looking at the
configdialog example from Trolltech. In that example a QListWidget is
used to display a column of icons with text under each one.  If the
text for an item is very long the widget ends up displaying the icons
in a non-aligned way.

Does anyone know if there is an easy way to control the maximum width
of the items in the QListWidget?  Also, is there a way to cause the
text on a list item to wrap to multiple lines if it is too wide for
the maximum width of the item?

Thanks

-- Bennett


On 2/1/07, Justin Powell <valkenar@xxxxxxxxx> wrote:
> Is it possible to left-align the icons in a QListWidget?  I've set the text
> alignment in each of the items, but don't see any way to do the same with the
> icons. The problem is that the position of the icon is based on the length of
> the text it's centered over. So with texts of different lengths, I'm ending up
> with a column of icons that are haphazardly aligned.
>
> If there's no way to set this directly, is there a convenient workaround?
>
>
>
> ____________________________________________________________________________________
> Food fight? Enjoy some healthy debate
> in the Yahoo! Answers Food & Drink Q&A.
> http://answers.yahoo.com/dir/?link=list&sid=396545367
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>


-- 
 [ signature omitted ] 

Message 8 in thread

Ralf Jung wrote:
> Using these options, linguist shows the umlauts correct. But even if the 
> translation is loaded by my application, the strings with the umlauts are not 
> translated (whereas the strings without umlauts are). It seems to me that tr 
> doesn't find the translated string if it contains UTF-8 characters.

Traditionally, there have been restrictions on what can be used as 
a key string in translations. I have no idea how Qt handles its translations
exactly, but staying within the 7 bit ASCII range has always been a good idea.

> What can I do to have the translation working?

Use what works for everybody else: Use English 7 bit ASCII strings
and provide a proper German translation. [This is also an improvement 
for maintanance in the long run as you'll find more people able and/or willing
to work with English sources than with German ones...]

Alternatively, use "7 bit German" (i.e. "ae", "oe", "ss" ...) in your sources
and provide translations into English and "real German".

Regards
Andre'

--
 [ signature omitted ] 

Message 9 in thread

Hi,

thank you very much for your answers.

I don't see why I should now start writing my applications in English - I 
always used German (including umlauts) directly in the source without 
problems (using Borland C++-Builder as IDE and compiler) as my applications 
are written for a  German homepage and so they normally don't need any 
translations. If I want to have an English translation, I can still provide 
one, but I won't use English in my source files. Then it is a better solution 
for me to use ISO-8859-1 as charset.

I just tried out trUtf8 (thank you for the hint) â it seems to work with my 
demo application! I'll just try it out for my other program. Now I don't even 
need the setCodec calls and the options in the pro-file :)

> Also see the warning in the documentation; if your source code is compiled 
> by someone not running in a UTF8 locale, then your german umlaut characters
> might get you interesting results.
What do you mean by "not running a UTF-8 locale"? That one does not have UTF-8 
as standard charset, or that one does not have any UTF-8 support at all? The 
ui files use UTF-8 by default, so they would also show the strange behaviour 
on these systems?

Thanks,
Ralf

--
 [ signature omitted ] 

Message 10 in thread

Hi,

> What do you mean by "not running a UTF-8 locale"? That one does not have UTF-8 
> as standard charset, or that one does not have any UTF-8 support at all? The 
> ui files use UTF-8 by default, so they would also show the strange behaviour 
> on these systems?

For example the behavior of the compiler itself might depend on the locale.

--
 [ signature omitted ]