Russian text to Qt console



  • 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!


  • Lifetime Qt Champion

    Hi,

    It's because in Qt5 these functions have been removed


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.