[Interest] How to fix encoding
Edgar Moraes Diniz
edgar.diniz at openmailbox.org
Tue Aug 26 15:32:45 CEST 2014
Hi,
I had this problem here in Brazil, too, but with Qt 5.0, perhaps that's
the same point.
To overcome this problem, I found two solutions:
1 (easier): Do you really have to use ODBC? Native drivers are
supposedly better and faster. Try using the native driver for your DB.
2 (not so easy): Go to the QODBC source file and replace every ocurrence
of:
QString::fromUtf8 -> QString::fromLocal8Bit
QString::toUtf8 -> QString::toLocal8Bit
I believe the sources are located in
$QT_SRC/qtbase/src/sql/drivers/odbc/
At least, that solved my problem, before I switched to native driver
(QOCI - no problems with it).
Hope it works. Best,
Edgar.
Em 26/08/2014 10:14, zdenko podobny escreveu:
> Hello,
>
> I try to retrieve strings from db with QODBC (QT 5.3.1 windows).
> Database locale is en_US.819 (and ODBC driver does not work if client locale is not set to en_US.819). Strings (stored by windows application in db) are cp1250 encoded.
>
> And instead of "doručené" I got "doru?en?".
>
> Here is part of my code:
>
> QTextCodec::setCodecForLocale(QTextCodec::codecForName("cp1250"));
>
> QTextCodec *codec_db = QTextCodec::codecForName("latin1");
>
> QSqlRecord rec = query.record();
>
> qDebug() << "test: " << "doručené";
>
> while (query.next()) {
>
> for (int x = 0; x < rec.count(); x++) {
>
> QVariant variant = query.value(x);
>
> if (rec.value(x).type() == QMetaType::QString) {
>
> QByteArray encodedString = codec_db->fromUnicode(variant.toByteArray());
>
> qDebug() << "db_str: " << encodedString;
>
> }
>
> }
>
> }
>
> How can I fix encoding of db output?
>
> PS: In python 3.4.1 I am able to get correct output (via pyodbc) with this:
>
> print("db_str:", db_str.encode('latin1').decode('cp1250'))
>
> But I would prefer to use C++ and QT5...
>
> Zdenko
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest [1]
--
/**
* @AUTHOR Edgar Moraes Diniz
*
* edgar.diniz at openmailbox.org
*/
Links:
------
[1] http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140826/a4da48d9/attachment.html>
More information about the Interest
mailing list