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


C++ QTextStream::setCodec方法代码示例

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


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

示例1: loadTPL

bool loadTPL(Translator &translator, QIODevice &dev, ConversionData &cd)
{
    // Hack: Check if the template is utf8
    QTextStream testStream;
    testStream.setDevice( &dev );
    QString testContent = testStream.readAll();
    if ( ( testContent.startsWith( QLatin1String("{*?template charset="), Qt::CaseInsensitive ) &&
           ( testContent.startsWith( QLatin1String("{*?template charset=utf8?*}"), Qt::CaseInsensitive ) ||
             testContent.startsWith( QLatin1String("{*?template charset=utf-8?*}"), Qt::CaseInsensitive ) ) ) ||
         cd.m_assumeUtf8 )
    {
        stream.setCodec( QTextCodec::codecForName("UTF-8") );
        stream.setAutoDetectUnicode( true );
    }
    else
    {
        stream.setCodec( QTextCodec::codecForLocale() );
        stream.setAutoDetectUnicode( false );
    }
    stream.setDevice( &dev );
    stream.seek( 0 ); // we need to rewind it because the testStream has read all data on the QIODevice

    parse( &translator, cd.m_sourceDir.path() + QDir::separator() + cd.m_sourceFileName );

    return true;
}
开发者ID:CSV007,项目名称:siliconnexion,代码行数:26,代码来源:tpl.cpp

示例2: speak

void Speech::speak(QString command, bool stdIn, const QString &text, const QString &language, int encoding, QTextCodec *codec) {
   if (text.length () > 0) {
      // 1. prepare the text:
      // 1.a) encode the text
      QTextStream ts (encText, IO_WriteOnly);
      if (encoding == Local)
         ts.setEncoding (QTextStream::Locale);
      else if (encoding == Latin1)
         ts.setEncoding (QTextStream::Latin1);
      else if (encoding == Unicode)
         ts.setEncoding (QTextStream::Unicode);
      else
         ts.setCodec (codec);
      ts << text;

      // 1.b) create a temporary file for the text
      tempFile.setAutoDelete(true);
      QTextStream* fs = tempFile.textStream();
      if (encoding == Local)
         fs->setEncoding (QTextStream::Locale);
      else if (encoding == Latin1)
         fs->setEncoding (QTextStream::Latin1);
      else if (encoding == Unicode)
         fs->setEncoding (QTextStream::Unicode);
      else
         fs->setCodec (codec);
      *fs << text;
      *fs << endl;
      QString filename = tempFile.file()->name();
      tempFile.close();

      // 2. prepare the command:
      command = prepareCommand (command, encText, filename, language);


      // 3. create a new process
      process << command;
      connect(&process, SIGNAL(processExited(KProcess *)), this, SLOT(processExited(KProcess *)));
      connect(&process, SIGNAL(wroteStdin(KProcess *)), this, SLOT(wroteStdin(KProcess *)));
      connect(&process, SIGNAL(receivedStdout(KProcess *, char *, int)), this, SLOT(receivedStdout(KProcess *, char *, int)));
      connect(&process, SIGNAL(receivedStderr(KProcess *, char *, int)), this, SLOT(receivedStderr(KProcess *, char *, int)));

      // 4. start the process
      if (stdIn) {
         process.start(KProcess::NotifyOnExit, KProcess::All);
         if (encText.size() > 0)
            process.writeStdin(encText, encText.size());
         else
            process.closeStdin();
      }
      else
         process.start(KProcess::NotifyOnExit, KProcess::AllOutput);
   }
开发者ID:,项目名称:,代码行数:53,代码来源:

示例3: notesDocument

QTextDocument* KateProject::notesDocument ()
{
  /**
   * already there?
   */
  if (m_notesDocument)
    return m_notesDocument;
  
  /**
   * else create it
   */
  m_notesDocument = new QTextDocument (this);
  m_notesDocument->setDocumentLayout (new QPlainTextDocumentLayout (m_notesDocument));
  
  /**
   * and load text if possible
   */
  if (QFile *inFile = projectLocalFile ("notes.txt")) {
    {
      QTextStream inStream (inFile);
      inStream.setCodec ("UTF-8");
      m_notesDocument->setPlainText (inStream.readAll ());
    }
    delete inFile;
  }

  /**
   * and be done
   */
  return m_notesDocument;
}
开发者ID:dividedmind,项目名称:kate,代码行数:31,代码来源:kateproject.cpp

示例4: saveResult

bool WordsCounter::saveResult (const QString &fileName) const
{
    QFile file (fileName);

    if (!file.open (QIODevice::WriteOnly)) {
        return false;
    }

    QTextStream stream (&file);
    stream.setCodec ("UTF-8");

    typedef QMultiMap<int, QString> SortByCount;
    SortByCount sortByCount;

    for (Words::const_iterator it = words_.begin(),
            end = words_.end(); it != end; ++it) {
        sortByCount.insert (it.value(), it.key());
    }

    for (SortByCount::const_iterator it = sortByCount.begin(),
            end = sortByCount.end(); it != end; ++it) {
        stream << it.value() << ": " << it.key() << endl;
    }

    return true;
}
开发者ID:panter-dsd,项目名称:WordsCounter,代码行数:26,代码来源:wordscounter.cpp

示例5: acceptImage

void ExtractImages::acceptImage(DomImage *image)
{
    QString format = image->elementData()->attributeFormat();
    QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower();
    QString fname = m_imagesDir.absoluteFilePath(image->attributeName() + QLatin1Char('.') + extension);

    *m_output << "        <file>images/" << image->attributeName() << QLatin1Char('.') + extension << "</file>\n";

    QFile f;
    f.setFileName(fname);
    const bool isXPM_GZ = format == QLatin1String("XPM.GZ");
    QIODevice::OpenMode openMode = QIODevice::WriteOnly;
    if (isXPM_GZ)
        openMode |= QIODevice::Text;
    if (!f.open(openMode)) {
        fprintf(stderr, "Could not create image file %s: %s", qPrintable(fname), qPrintable(f.errorString()));
        return;
    }

    if (isXPM_GZ) {
        QTextStream *imageOut = new QTextStream(&f);
        imageOut->setCodec(QTextCodec::codecForName("UTF-8"));

        CPP::WriteIconData::writeImage(*imageOut, QString(), image);
        delete imageOut;
    } else {
        CPP::WriteIconData::writeImage(f, image);
    }

    f.close();
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例6: openFile

bool TextManager::openFile(const QString &filePath, const QString &generatorName, const text::LanguageInfo &language)
{
	QFile file(filePath);
	QTextStream *inStream = nullptr;

	if (!file.isOpen() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
		inStream = new QTextStream(&file);
		inStream->setCodec(QTextCodec::codecForName("UTF-8"));

		QScintillaTextEdit *area = new QScintillaTextEdit();

		area->setCurrentLanguage(language);
		area->setText(inStream->readAll());
		mText.insert(filePath, area);
		mPath.insert(area, filePath);
		mPathType.insert(filePath, true);
		mModified.insert(filePath, QPair<bool, bool>(false, false));
		mGeneratorName.insert(filePath, generatorName);
		mCodeBlockManager.addNewCode(filePath);

		connect(area, SIGNAL(textWasModified(text::QScintillaTextEdit*))
				, this, SLOT(setModified(text::QScintillaTextEdit*)));

		return true;
	}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例7: importFromTxt

bool Deck::importFromTxt(QString fileName)
{
    const QChar sep('\t');
    QTextStream s;
    QFile file(fileName);

    file.open(QIODevice::ReadOnly | QIODevice::Text);

    if(!file.isOpen())
        return false;

    s.setDevice(&file);
    s.setCodec("UTF-8");

    QStringList sl;
    QString l = s.readLine();
    while (!s.atEnd()) {
        sl = l.split(sep);

        if(sl.size()>1) {
            Card *card = new Card();

            card->updateFront(sl[0]);
            card->updateBack(sl[1]);

            addCard(card);
        }

        l = s.readLine();
    };
    
    return true;
}
开发者ID:m-o-s-t-a-f-a,项目名称:dana,代码行数:33,代码来源:deck.cpp

示例8: saveDocument

bool AtomicXmlFile::saveDocument(const QDomDocument& doc, QString fileName) const
{
	bool result = false;

	QFile file(fileName);
	if (!file.open(QIODevice::WriteOnly)) {
		return result;
	}

	QTextStream text;
	text.setDevice(&file);
	text.setCodec("UTF-8");
	text << doc.toString();

	result = file.error() == QFile::NoError;
	file.close();

	// QFile error checking should be enough, but to be completely sure that
	// XML is well-formed we could try to parse data we just had written:
	// if (result) {
	// 	QDomDocument temp;
	// 	result = loadDocument(&temp, fileName);
	// }

	return result;
}
开发者ID:AlekSi,项目名称:Jabbin,代码行数:26,代码来源:atomicxmlfile.cpp

示例9: startFile

void CsvExporter::startFile(QIODevice *file, const QString& encoding, const QString& title)
{
	Q_UNUSED(title);
	// Output stream in requested encoding
	m_out = new QTextStream(file);
	m_out->setCodec(QTextCodec::codecForName(encoding.toUtf8()));
}
开发者ID:callaa,项目名称:KQueryBrowser,代码行数:7,代码来源:csvexporter.cpp

示例10: file

void PluginBc_CuentasAnuales2ODS::balanceSituacionODS ( CAnuales tipus )
{
    BL_FUNC_DEBUG
    /// Se genera el Balance de Situacion en formato ODS (Hoja de calculo OpenOffice.org).

    /// BUG: Se necesita usar .toQString('.') porque sino los decimales no
    /// aparecen bien en OpenOffice. Creo que es un bug del script de conversion de .py a .ods
    QString archivosalida;
    bool error = false;
    switch ( tipus ) {
    case CAAASL:
        archivosalida = cuentaAnualAsociancionSinLucro ();
        break;

    case CAPGC07:
        archivosalida = cuentaAnualCAPGC07();
        break;

    case CAPYMES08:
        archivosalida = cuentaAnualCAPYMES08();
        break;

    case CAAPGC08:
        archivosalida = cuentaAnualCAAPGC08();
        break;

    case CAPGC08:
        archivosalida = cuentaAnualCAPGC08();
        break;

    default:
        blMsgError ( _ ( "ERROR: Funcion no implementada todavia." ) );
        break;
    }

    QString archivod = g_confpr->value( CONF_DIR_USER ) + "canualesods.py";

    QString cadena = "rm " + g_confpr->value( CONF_DIR_USER ) + "canualesods.ods";
    system ( cadena.toLatin1() );
    cadena = "rm " + archivod;
    system ( cadena.toLatin1() );

    QFile file ( archivod );
    if ( file.open ( QIODevice::WriteOnly ) ) {
        QTextStream stream ( &file );
        stream.setCodec ( "UTF-8" );
        stream << archivosalida.toLatin1();
        file.close();
    } else
        blMsgError ( _ ( "ERROR: No se ha podido crear el archivo" ) );

    cadena = " cd " + g_confpr->value( CONF_DIR_USER ) + "; python " + archivod;
    system ( cadena.toLatin1() );
    cadena = g_confpr->value( CONF_ODS ) + " " + g_confpr->value( CONF_DIR_USER ) + "canualesods.ods &";
    system ( cadena.toLatin1() );
    
}
开发者ID:JustDevZero,项目名称:bulmages,代码行数:57,代码来源:pluginbc_cuentasanuales2ods.cpp

示例11: writeDeck

void FlashcardsDeck::writeDeck (QTextStream& stream)
{
	stream.setCodec("UTF-8");

	for (unsigned i = 0; i < usedColumns.size(); i++)
		stream << usedColumns[i] << ((i + 1) == usedColumns.size() ? "\n" : "\t");

	for (std::map <int, QString>& row : exportData)
		for (unsigned i = 0; i < usedColumns.size(); i++)
			stream << row[i] << ((i + 1) == usedColumns.size() ? "\n" : "\t");
}
开发者ID:nikita-uvarov,项目名称:te-exporter,代码行数:11,代码来源:DatabaseExporter.cpp

示例12: beginSubPage

void PageGenerator::beginSubPage(const Location& location,
                                 const QString& fileName)
{
    QFile *outFile = new QFile(outputDir() + "/" + fileName);
    if (!outFile->open(QFile::WriteOnly))
	location.fatal(tr("Cannot open output file '%1'")
			.arg(outFile->fileName()));
    QTextStream *out = new QTextStream(outFile);
    out->setCodec("ISO-8859-1");
    outStreamStack.push(out);
}
开发者ID:Fale,项目名称:qtmoko,代码行数:11,代码来源:pagegenerator.cpp

示例13: qstring_save

bool qstring_save (const QString &fileName, const QString &data, const char *enc)
{
  QFile file (fileName);
  if (! file.open (QFile::WriteOnly | QFile::Text))
      return false;

  QTextStream out (&file);
  out.setCodec (enc);
  out << data;

  return true;
}
开发者ID:ViktorNova,项目名称:eko-1,代码行数:12,代码来源:utils.cpp

示例14: openAndBackupLogFile

// 打开日志文件 log.txt,如果不是当天创建的,则使用创建日期把其重命名为 yyyy-MM-dd.log,并重新创建一个 log.txt
void LogHandlerPrivate::openAndBackupLogFile() {
    // 总体逻辑:
    // 1. 程序启动时 logFile 为 NULL,初始化 logFile,有可能是同一天打开已经存在的 logFile,所以使用 Append 模式
    // 2. logFileCreatedDate is null, 说明日志文件在程序开始时不存在,所以记录下创建时间
    // 3. 程序运行时检查如果 logFile 的创建日期和当前日期不相等,则使用它的创建日期重命名,然后再生成一个新的 log.txt 文件
    makeSureLogDirectory(); // 如果日志所在目录不存在,则创建
    QString logPath = logDir.absoluteFilePath("log.txt"); // 日志的路径
    // [[1]] 程序启动时 logFile 为 NULL
    if (NULL == logFile) {
        logFile = new QFile(logPath);
        logOut  = (logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) ?  new QTextStream(logFile) : NULL;

        if (NULL != logOut) {
            logOut->setCodec("UTF-8");
        }

        // [[2]] 如果文件是第一次创建,则创建日期是无效的,把其设置为当前日期
        if (logFileCreatedDate.isNull()) {
            logFileCreatedDate = QDate::currentDate();
        }
        // TODO: 可以检查日志文件超过 30 个,删除 30 天前的日志文件
    }
    // [[3]] 程序运行时如果创建日期不是当前日期,则使用创建日期重命名,并生成一个新的 log.txt
    if (logFileCreatedDate != QDate::currentDate()) {
        logFile->flush();
        logFile->close();
        delete logOut;
        delete logFile;
        QString newLogPath = logDir.absoluteFilePath(logFileCreatedDate.toString("yyyy-MM-dd.log"));;
        QFile::copy(logPath, newLogPath); // Bug: 按理说 rename 会更合适,但是 rename 时最后一个文件总是显示不出来,需要 killall Finder 后才出现
        QFile::remove(logPath); // 删除重新创建,改变创建时间
        logFile = new QFile(logPath);
        logOut  = (logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) ?  new QTextStream(logFile) : NULL;
        logFileCreatedDate = QDate::currentDate();

        if (NULL != logOut) {
            logOut->setCodec("UTF-8");
        }
    }
}
开发者ID:xtuer,项目名称:Qt,代码行数:41,代码来源:LogHandler.cpp

示例15: read

bool docengine::read(QIODevice *io, QsciScintillaqq* sci, QString encoding)
{
    if( !sci )                          return false;
    if(!io->open(QIODevice::ReadOnly))  return false;
    QFile *file = static_cast<QFile*>(io);
    QFileInfo fi(*file);

    QString readEncodedAs = generalFunctions::getFileMimeEncoding(fi.absoluteFilePath());
    QTextStream stream ( io );
    QString txt;

    stream.setCodec((encoding != "") ? encoding.toUtf8() : readEncodedAs.toUtf8());
    stream.setCodec(readEncodedAs.toUtf8());

    txt = stream.readAll();
    io->close();

    sci->clear();
    sci->append(txt);

    return true;
}
开发者ID:aadityakalsi,项目名称:notepadqq,代码行数:22,代码来源:docengine.cpp


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