0

I try to call an OLE object with parameters - Russian characters, but as a result I get a bad encoding at the output (the OLE driver logs requests). Supported encoding Windows-1251 and UTF-8, but can't send text correctly. I do this:

setlocale(LC_ALL, "Russian");

    QString fileToPrint = (qApp->applicationDirPath()+"/"+"test.txt";

       QFile filePrt(fileToPrint);

          QTextStream inPrt(& filePrt);
          inPrt.setCodec("Windows-1251");

          if(!filePrt.open(QFile::ReadOnly | QFile::Text))
          {
              qDebug() << "File failed to open";
              return;
          }

         QStringList toPrint = inPrt.readAll().trimmed().split("\n");

QByteArray strEncSend;

strEncSend+=toPrint [i].replace("\f", "");

object.dynamicCall("FreeTextLine(\""+strEncSend+"\")");

but in logs I get:

02.11.2021 12:25:17.87|Debug|вызов отработан: FreeTextLine("???°?????µ?»?°?", None) = Success

I also tried it through:

QTextCodec *codec = QTextCodec::codecForName("windows-1251");
                QByteArray strEnc = codec->fromUnicode(toPrint [i].replace("\f", ""));

Please help, how to set the encoding correctly? Thanks!

user16791596
  • 31
  • 1
  • 3
  • And that FreeTextLine is some COM object method? What text encoding does it expect? Can you hardcode this object.dynamicCall("FreeTextLine(\"правильный текст\")) and see the expected result? – Alexander V Nov 02 '21 at 19:18
  • yes, FreeTextLine is COM object method. object.dynamicCall("FreeTextLine(\"правильный текст\")) is the same - wrong encoding – user16791596 Nov 02 '21 at 19:53
  • Not really Qt problem? Find out what text encoding works first then? Or what text? – Alexander V Nov 02 '21 at 23:30
  • try `QTextCodec::codecForName("KOI8-R")` – Vahagn Avagyan Nov 03 '21 at 00:38
  • QTextCodec::codecForName("KOI8-R") - the same. I think it's Qt trouble, on Java all is ok – user16791596 Nov 03 '21 at 08:17
  • Then it does seem to be encoding. Try using UTF-8 or what Java returns for Charset.defaultCharset() See https://stackoverflow.com/questions/1006276/what-is-the-default-encoding-of-the-jvm – Alexander V Nov 03 '21 at 15:53

0 Answers0