[Interest] How to fix encoding
zdenko podobny
zdenop at gmail.com
Tue Aug 26 15:14:32 CEST 2014
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140826/75b94f4c/attachment.html>
More information about the Interest
mailing list