Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Russian text to Qt console
Qt 6.11 is out! See what's new in the release blog

Russian text to Qt console

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by
    #1

    Hi,

    It works for Qt 4.8.5. But doesn't work for Qt 5

    Console_Russian_Hello_World_for_Qt5.pro
    [code]
    SOURCES +=
    main.cpp

    CONFIG += console
    CONFIG -= app_bundle
    QT -= gui
    [/code]

    main.cpp
    [code]
    #include <QCoreApplication>
    #include <QDebug>
    #include <QTextCodec>
    #include <QTextStream>

    QTextStream cin(stdin);
    QTextStream cout(stdout);

    void sayhellow(const QString& s) {
    QTextStream out(stdout);
    #if defined(Q_WS_WIN)
    out.setCodec("IBM866");
    #endif
    out << s << endl;
    out.flush();
    }

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QTextCodec * codec;
    codec = QTextCodec::codecForName("utf-8");
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForTr(codec);
    
    QString s = "Привет, Мир!";
    sayhellow(s);
    
    return a.exec&#40;&#41;;
    

    }

    [/code]

    Output
    [code]
    D:\Documents\Qt\QtExamples\0057_Console_Russian_Hello_World_Qt5\Console_Russian_Hello_World_Qt5\main.cpp:24: error: 'setCodecForCStrings' is not a member of 'QTextCodec'
    QTextCodec::setCodecForCStrings(codec);
    ^

    D:\Documents\Qt\QtExamples\0057_Console_Russian_Hello_World_Qt5\Console_Russian_Hello_World_Qt5\main.cpp:26: error: 'setCodecForTr' is not a member of 'QTextCodec'
    QTextCodec::setCodecForTr(codec);
    ^
    [/code]

    Thank you!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It's because in Qt5 these functions have been removed

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved