db.setConnectOptions("CHARSET=WIN1251");
#define TRANSACTION(x) (QSqlDatabase::database().driver()->setProperty("Transaction",(x)))#define TRANS_SELECT "TAM=amRead, TIL=ilReadCommitted, TLR=lrNoWait, TFF=0"#define TRANS_UPDATE "TAM=amWrite, TIL=ilConcurrency, TLR=lrNoWait, TFF=0"#define TRANS_REPORT "TAM=amRead, TIL=ilConcurrency, TLR=lrNoWait, TFF=0"#define TRANS_DEFAULT "TAM=amWrite, TIL=ilConcurrency, TLR=lrWait, TFF=0"// ............. TRANSACTION(TRANS_SELECT); QSqlQuery query.prepare(".........
#include <QTextCodec>class CTextCodecWIN1251 : public QTextCodec{private: QTextCodec *win1251Codec;public: CTextCodecWIN1251(); ~CTextCodecWIN1251(); virtual QByteArray name() const; virtual QList<QByteArray> aliases() const; virtual int mibEnum() const;protected: virtual QByteArray convertFromUnicode( const QChar * input, int number, ConverterState * state ) const; virtual QString convertToUnicode( const char * chars, int len, ConverterState * state ) const;};CTextCodecWIN1251::CTextCodecWIN1251(){ win1251Codec = QTextCodec::codecForName("Windows-1251");}CTextCodecWIN1251::~CTextCodecWIN1251(){}QByteArray CTextCodecWIN1251::convertFromUnicode(const QChar * input, int number, ConverterState * state) const{ if(!win1251Codec) return QByteArray(); return win1251Codec->fromUnicode(input, number, state);}QString CTextCodecWIN1251::convertToUnicode(const char * chars, int len, ConverterState * state) const{ if(!win1251Codec) return QString(); return win1251Codec->toUnicode(chars, len, state);}QByteArray CTextCodecWIN1251::name() const{ return QByteArray("WIN1251");}QList<QByteArray> CTextCodecWIN1251::aliases() const{ QList<QByteArray> list; list << QByteArray("WIN-1251") // Эти алиасы не обязательны << QByteArray("CP1251") << QByteArray("CP-1251") << QByteArray("1251"); return list;}int CTextCodecWIN1251::mibEnum() const{ if(!win1251Codec) return 0; return 2251;}... CTextCodecWIN1251 * p = new CTextCodecWIN1251();... db.setConnectOptions("ISC_DPB_LC_CTYPE=WIN1251");