Monthly Archives: September 2007

Qt 4 and iconv(3) mini-HOWTO

Qt 4 since 4.2.0 uses iconv(3) for QTextCodec::codecForLocale() unless thou disablest it with -no-iconv configure option. This leadeth to the two things: name() for this codec returneth “System” and QTextCodec::codecForLocale() just stoppeth working. Try to encode or decode something outside of US-ASCII with it, and thou wilt get either empty string or just US-ASCII characters from it, if there were any.

Here is the fix:

#include <locale.h>
setlocale(LC_ALL, “”) // this goeth to thy main()

The nature of the problem is described in the glibc manual:

A C program inherits its locale environment variables when it starts up.
This happens automatically. However, these variables do not
automatically control the locale used by the library functions, because
ISO C says that all programs start by default in the standard C'
locale. To use the locales specified by the environment, you must call
setlocale’. Call it as follows:

setlocale (LC_ALL, “”);

Задачка с числами

95 99 3
96 29 3
25 46 1
11 11 0
36 68 4
46 33 1
70 14 1
37 42 0
34 66 2
55 86 3
10 41 1
98 27 3
64 40 2
22 22 0
56 98 4
28 67 3
99 99 4
54 57 0
61 21 1
44 44 0
19 20 2
23 24 0
43 72 0
66 66 4
50 96 3
25 81 ?

Не знаю, смог бы я её решить без подсказок, но та сволочь, которая притащила её на работу, молчать не умеет в принципе, и уже через минуту брякнула, что