当前位置: 首页>>代码示例>>C++>>正文


C++ QTextCodec::makeEncoder方法代码示例

本文整理汇总了C++中QTextCodec::makeEncoder方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCodec::makeEncoder方法的具体用法?C++ QTextCodec::makeEncoder怎么用?C++ QTextCodec::makeEncoder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextCodec的用法示例。


在下文中一共展示了QTextCodec::makeEncoder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
    qputenv("LC_ALL", "C");
    QCoreApplication app(argc, argv);

    QString string(QChar(0x410));
    QTextCodec *locale = QTextCodec::codecForLocale();
    QTextEncoder *encoder = locale->makeEncoder();
    QByteArray output = encoder->fromUnicode(string);
    printf("%s\n", output.data());

    return 0;
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:13,代码来源:main.cpp

示例2: CheckMeCabHome

//------------------------------------------------------------------------------
bool MainWindow::CheckMeCabHome(QSettings *ini_settings)
{
    bool stat = true;
    QString meCabStdDir, meCabStdDir_x86;

    QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
    QTextEncoder *encoder = codec->makeEncoder();

    QDir dir(meCabHome);
    if(! dir.exists()){
        meCabStdDir_x86 = "c:/Program Files (x86)/MeCab/bin/";
        QDir dir_x86(meCabStdDir_x86);
        meCabStdDir = "c:/Program Files/MeCab/bin/";
        QDir dir(meCabStdDir);
        if(dir_x86.exists()){
            meCabHome = meCabStdDir_x86;
        }
        else if(dir.exists()){
            meCabHome = meCabStdDir;
        }
        else{
            QMessageBox::StandardButton reply;
            reply = QMessageBox::critical(this, tr("ERROR"),
                tr("MeCab is not installed in the folder below.") + "\n" +
                " " + meCabStdDir + "\n" +
                " " + tr("nor") + "\n" +
                " " + meCabStdDir_x86 + "\n\n" +
                tr("Install MeCab.") + "\n" +
                tr("If MeCab is installed in another folder, Change ini file.") + "\n" +
                " " + tr("ini file name") + ": " + programName + ".ini\n" +
                " " + tr("section") + ": [MeCab]\n" +
                " " + tr("name") + ": MeCab_HOME\n" +
                " " + tr("ex.") + " MeCab_HOME=C:/Program Files (x86)/MeCab/bin/\n"
                ,QMessageBox::Abort);
            meCabHome = "";
        }
        if(meCabHome != ""){
            ini_settings->setValue("MeCab/MeCab_HOME", QString(encoder->fromUnicode(meCabHome)));
        }
        else{
            stat = false;
        }
    }
    return stat;
}
开发者ID:hiromasah,项目名称:personal-information-mask-tool,代码行数:46,代码来源:mainwindow.cpp

示例3: editOutputFile

//------------------------------------------------------------------------------
bool MainWindow::editOutputFile(QString inputPath, QString meCabOutputPath, QString outputPath, QString maskColumnNo)
{
    bool stat = true;
    QString errmsg = "";
    int col = 0;
    QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
    QTextDecoder *decoder = codec->makeDecoder();
    QTextEncoder *encoder = codec->makeEncoder();
    
    QFile wfile(outputPath);
    QFile rfileMeCab(meCabOutputPath);
    QFile rfile(inputPath);
    if (wfile.open(QIODevice::WriteOnly | QIODevice::Text)){
        if (rfileMeCab.open(QIODevice::ReadOnly | QIODevice::Text)){
            if(maskColumnNo != ""){
                if (rfile.open(QIODevice::ReadOnly | QIODevice::Text)){
                    bool ok;
                    col = maskColumnNo.toInt(&ok, 10);
                    if(! ok){
                        errmsg = tr("Illegal Mask Column No.") + "(" + maskColumnNo + ")";
                        rfile.close();
                        stat = false;
                    }
                }
                else{
                    // Can't open input file.
                    errmsg = tr("Can't open the intput file.") + "(" + inputPath + ")";
                    stat = false;
                }
            }
            
            if(stat){
                QString outline = "";
                while (!rfileMeCab.atEnd()) {
                    QByteArray line = rfileMeCab.readLine();
                    //QString str = decoder->toUnicode(line);
                    QString str = line;
                    if(str == "EOS\n"){
                        if(maskColumnNo != ""){
                            QByteArray wline = rfile.readLine();
                            str = wline;
                            QStringList wlist = str.split("\t", QString::KeepEmptyParts, Qt::CaseSensitive);
                            str = outline;
                            outline = "";
                            for(int ii = 0; ii < wlist.count(); ii++){
                                if(outline != ""){
                                    outline += "\t";
                                }
                                if(ii == col){
                                    outline += str;
                                }
                                else{
                                    outline += wlist[ii];
                                }
                            }
                        }
                        wfile.write((outline + "\n").toAscii());
                        outline = "";
                    }
                    else{
                        QStringList wlist = str.split("\t", QString::KeepEmptyParts, Qt::CaseSensitive);
                        if(wlist[1].left(13) == "����,�ŗL����"){
                            QString unicodeStr = decoder->toUnicode(wlist[0].toAscii());
                            QString maskStr = unicodeStr.replace(QRegExp("."), decoder->toUnicode("��"));
                            outline += encoder->fromUnicode(maskStr);
                        }
                        else{
                            outline += wlist[0];
                        }
                    }
                }
                rfileMeCab.close();
                if(maskColumnNo != ""){
                    rfile.close();
                }
            }
        }
        else{
            // Can't open MeCab output file.
            errmsg = tr("Can't open the MeCab output file.") + "(" + meCabOutputPath + ")";
            stat = false;
        }
        
        wfile.close();
    }
    else{
        // Can't open the output file.
        errmsg = tr("Can't open the output file.") + "(" + outputPath + ")";
        stat = false;
    }
    
    if(! stat){
        QMessageBox::StandardButton reply;
        reply = QMessageBox::critical(this, tr("ERROR"),
            errmsg,
            QMessageBox::Abort);
        if (reply == QMessageBox::Abort){
            close();
        }
//.........这里部分代码省略.........
开发者ID:hiromasah,项目名称:personal-information-mask-tool,代码行数:101,代码来源:mainwindow.cpp


注:本文中的QTextCodec::makeEncoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。