[Interest] How to fix encoding

Edgar Moraes Diniz edgar.diniz at openmailbox.org
Tue Aug 26 15:58:58 CEST 2014


 

Hi, 

Actually, I meant Qt drivers, such as QOCI, QPSQL, QSQLITE etc. 

You don't need to recompile the entire Qt library, only the QODBC
driver. 

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/05118bfb/attachment.html>


More information about the Interest mailing list