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


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

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


在下文中一共展示了QTextStream::setAutoDetectUnicode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readListFile

ModList::OrderList ModList::readListFile()
{
	OrderList itemList;
	if (m_list_file.isNull() || m_list_file.isEmpty())
		return itemList;

	QFile textFile(m_list_file);
	if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text))
		return OrderList();

	QTextStream textStream;
	textStream.setAutoDetectUnicode(true);
	textStream.setDevice(&textFile);
	while (true)
	{
		QString line = textStream.readLine();
		if (line.isNull() || line.isEmpty())
			break;
		else
		{
			OrderItem it;
			it.enabled = !line.endsWith(".disabled");
			if (!it.enabled)
			{
				line.chop(9);
			}
			it.id = line;
			itemList.append(it);
		}
	}
	textFile.close();
	return itemList;
}
开发者ID:ACGaming,项目名称:MultiMC5,代码行数:33,代码来源:ModList.cpp

示例3: os

void HttpServer :: replyGet(QTcpSocket *socket, QString const &req)
{
  QTextStream os (socket);
  os.setAutoDetectUnicode (true);
  QDir const dir (d->path.path() + req);
  auto contentFile = dir.canonicalPath();
  QFileInfo const info(contentFile);
  
  if (!info.exists() || !info.isFile() || !info.isReadable()) {
    os << "HTTP/1.0 404 Not Found\r\n"
      "\r\n";
  } else {
    
    auto size = QString::number(info.size());
    auto lastModified = info.lastModified().toString();
    auto suffix  = info.suffix();

    QFile file(contentFile);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
      os << "HTTP/1.0 404 Not Found\r\n"
	"\r\n";
    }
    
    os << "HTTP/1.1 200 Ok\r\n"
      "Date: " << QDate::currentDate().toString() << "\r\n"
      "Last-Modified: " << lastModified << "\r\n"
      "Content-Type: text/html; charset=\"UTF-8\"\r\n"
      "Content-Length: " << size << "\r\n"
      "\r\n";
      
    QTextStream in(&file);
    while (!in.atEnd()) {
      os << in.readLine() << "\n";
    }
  }
  
  socket->close();

  if (socket->state() == QTcpSocket::UnconnectedState) {
    delete socket;
  }
}
开发者ID:NanoSim,项目名称:Porto,代码行数:42,代码来源:httpserver.cpp

示例4: loadXmlFromFile

QString BtBookmarkLoader::loadXmlFromFile(QString fileName)
{
	if (fileName.isNull()) {
		fileName = util::filesystem::DirectoryUtil::getUserBaseDir().absolutePath() + "/bookmarks.xml";
	}
	QFile file(fileName);
	if (!file.exists())
		return QString();

	QString xml;
	if (file.open(QIODevice::ReadOnly)) {
		QTextStream t;
		t.setAutoDetectUnicode(false);
		t.setCodec(QTextCodec::codecForName("UTF-8"));
		t.setDevice(&file);
		xml = t.readAll();
		file.close();
	}
	return xml;
}
开发者ID:bibletime,项目名称:historic-bibletime-svn,代码行数:20,代码来源:btbookmarkloader.cpp


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