qDebug(qPrintable(someQstringInUTF8));
C++ (Qt)#include <QCoreApplication>#include <QDebug> int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QString string = "Привет мир !"; qDebug() << qPrintable(string.toUtf8()); return a.exec();}
C++ (Qt)#include <QCoreApplication>#include <QDebug>#include <QTextCodec>#include <QTextStream>#include <iostream> QTextStream cin(stdin);QTextStream cout(stdout); int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QString string = "Привет, Мир!"; QTextCodec *codec = QTextCodec::codecForName("CP866"); // std::cout QByteArray encodedString = codec->fromUnicode(string); std::cout << "std::cout = " << encodedString.data() << std::endl; // TextStream cout.setCodec(codec); cout << "TextStream = " << string << "\n"; cout.flush(); // qDebug QTextCodec::setCodecForLocale(codec); qDebug() << "qDebug() = " << string; // Console r/w cout << "Enter a text: "; cout.flush(); cin.setCodec(codec); QString inputStr; // Read data from a console cin >> inputStr; cout << "From a console = " << inputStr << endl; cout.flush(); return a.exec();}
C++ (Qt)QString string = "Привет мир !";QTextCodec *codec = QTextCodec::codecForName("CP866");QByteArray encodedString = codec->fromUnicode(string);std::cout << encodedString.data();
C++ (Qt)#ifndef SHOWER_H#define SHOWER_H #include <iostream> #include <QObject>#include <QString>#include <QTextCodec>#include <QByteArray> class Shower : public QObject{ Q_OBJECT public slots: void show( QString *content ) { QTextCodec *codec = QTextCodec::codecForName("CP866"); QByteArray encodedString = codec->fromUnicode( *content ); std::cout << encodedString.data( ) << std::endl; }}; #endif // SHOWER_H
C++ (Qt)#include <iostream>#include <QTextCodec>#include <QObject> #define STR(s) ((QTextCodec::codecForLocale()->fromUnicode(s)).constData()) int main(){ std::cout << STR( QObject::tr( "Привет, Мир!" ) );}