本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}