Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5219 closed Bug (fixed)

QPrintable and non Latin-1 symbols on Ubuntu

Reported by: krab Owned by: jordan
Priority: Normal Milestone: 2.77
Component: Qt Client Version: 2.76
Severity: Normal Keywords: interface, letters, linux
Cc:

Description

From this disscussion https://trac.transmissionbt.com/ticket/3570

Bug about МБ/Ñ in interface its ONLY transmission-qt+ubuntu (dont know about others linux distro). Bug when you use

    tr_formatter_speed_init( speed_K,
                             qPrintable( unitStrings[SPEED][KB] ),
                             qPrintable( unitStrings[SPEED][MB] ),
                             qPrintable( unitStrings[SPEED][GB] ),
                             qPrintable( unitStrings[SPEED][TB] ) );

P.S.

void QTextCodec::setCodecForCStrings ( QTextCodec * codec ) [static]

Sets the codec used by QString to convert to and from const char * and QByteArrays. If the codec is 0 (the default), QString assumes Latin-1.

Attachments (1)

01_formatter.cc (2.9 KB) - added by rb07 8 years ago.
Simple fix.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 8 years ago by krab

When you use qPrintable without setCodecForCStrings.

comment:2 Changed 8 years ago by jordan

Looks like Qt 5 removes QTextCodec::setCodecForStrings and implicitly assumes thta everything's UTF-8:

http://www.macieira.org/blog/2012/05/source-code-must-be-utf-8-and-qstring-wants-it/

comment:3 Changed 8 years ago by krab

In Ubuntu Qt 4.8.x O_o

comment:4 Changed 8 years ago by krab

#if QT_VERSION < 0x050000
#if defined (Q_OS_LINUX)
   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
#endif

And #include<QTextCodec> anyway.

Last edited 8 years ago by krab (previous) (diff)

Changed 8 years ago by rb07

Simple fix.

comment:5 Changed 8 years ago by rb07

I've attached a fix that solves the Russian translation problem that we have been discussing.

The fix is based on the problem diagnosed in this ticket, qPrintable produces a string (as char *) that is not usable with translations like the Russian one.

qPrintable(s) is defined as s.toLocal8bit().constData(), which could be any 8-bit code. The simple solution is to get rid of qPrintable() and use UTF-8 as standard. The patch was tested with the Russian translation (no other change to the code) and it works fine.

I also tried the more simple approach, which is to return QStrings converted with fromLocal8bit(), it didn't work (with the Russian translation), the mixture of ASCII (or UTF-8) returned by tr_formatter_speed_KBps() for instance was not converted right, in fact nothing changed.

comment:6 Changed 8 years ago by jordan

\o/

comment:7 Changed 8 years ago by krab

Yes, such variant works. Checked. But still can not see a difference with QPrintable + setCodecForCStrings. :)

comment:8 Changed 8 years ago by rb07

There's another use of qPrintable that may be worth getting rid of, in session.cc:977, the function Session :: addNewlyCreatedTorrent() uses it to send the path.

I rather use (not tested)

    tr_variantDictAddStr( args, TR_KEY_download_dir, localPath.toUtf8().constData() );

to avoid the problem with paths with non-ASCII characters (libtransmission already handles all paths in UTF-8).

Last edited 8 years ago by rb07 (previous) (diff)

comment:9 follow-up: Changed 8 years ago by jordan

  • Milestone changed from None Set to 2.80
  • Status changed from new to assigned

comment:10 Changed 8 years ago by jordan

  • Resolution set to fixed
  • Status changed from assigned to closed

formatter.cc and session.cc changes added in r13799.

The session.cc:977 change Works For Me, although to be fair I'm only using English characters here...

comment:11 in reply to: ↑ 9 Changed 8 years ago by rb07

Replying to jordan:

Looks like the comment's text disappeared, replying to the email:

rb07, I think the foo.toUtf8().constData() calls are going to be dangling pointers, similar to the bug in my code that Valgrind found, tracked in bug #5192

They are volatile, but I think it was the same with qPrintable so I didn't check if libtransmission does a strdup() or similar. Ref. http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qPrintable

comment:12 Changed 8 years ago by jordan

  • Milestone changed from 2.80 to 2.77

comment:13 Changed 8 years ago by jordan

r13919: backport r13799 for bug #5219

Note: See TracTickets for help on using tickets.