本文整理汇总了C++中QTextStream::setGenerateByteOrderMark方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::setGenerateByteOrderMark方法的具体用法?C++ QTextStream::setGenerateByteOrderMark怎么用?C++ QTextStream::setGenerateByteOrderMark使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::setGenerateByteOrderMark方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveListFile
bool ModList::saveListFile()
{
if (m_list_file.isNull() || m_list_file.isEmpty())
return false;
QFile textFile(m_list_file);
if (!textFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
return false;
QTextStream textStream;
textStream.setGenerateByteOrderMark(true);
textStream.setCodec("UTF-8");
textStream.setDevice(&textFile);
for (auto mod : mods)
{
textStream << mod.mmc_id();
if (!mod.enabled())
textStream << ".disabled";
textStream << endl;
}
textFile.close();
return false;
}
示例2: save
bool TextBuffer::save (const QString &filename)
{
// codec must be set!
Q_ASSERT (m_textCodec);
/**
* construct correct filter device and try to open
*/
QIODevice *file = KFilterDev::deviceForFile (filename, m_mimeTypeForFilterDev, false);
if (!file->open (QIODevice::WriteOnly)) {
delete file;
return false;
}
/**
* construct stream + disable Unicode headers
*/
QTextStream stream (file);
stream.setCodec (QTextCodec::codecForName("UTF-16"));
// set the correct codec
stream.setCodec (m_textCodec);
// generate byte order mark?
stream.setGenerateByteOrderMark (generateByteOrderMark());
// our loved eol string ;)
QString eol = "\n"; //m_doc->config()->eolString ();
if (endOfLineMode() == eolDos)
eol = QString ("\r\n");
else if (endOfLineMode() == eolMac)
eol = QString ("\r");
// just dump the lines out ;)
for (int i = 0; i < m_lines; ++i)
{
// get line to save
Kate::TextLine textline = line (i);
// strip trailing spaces
if (m_removeTrailingSpaces)
{
int lastChar = textline->lastChar();
if (lastChar > -1)
{
stream << textline->text().left (lastChar+1);
}
}
else // simple, dump the line
stream << textline->text();
// append correct end of line string
if ((i+1) < m_lines)
stream << eol;
}
// flush stream
stream.flush ();
// close and delete file
file->close ();
delete file;
#ifndef Q_OS_WIN
// ensure that the file is written to disk
// we crete new qfile, as the above might be wrapper around compression
QFile syncFile (filename);
syncFile.open (QIODevice::ReadOnly);
#ifdef HAVE_FDATASYNC
fdatasync (syncFile.handle());
#else
fsync (syncFile.handle());
#endif
#endif
// did save work?
bool ok = stream.status() == QTextStream::Ok;
// remember this revision as last saved if we had success!
if (ok)
m_history.setLastSavedRevision ();
// report CODEC + ERRORS
kDebug (13020) << "Saved file " << filename << "with codec" << m_textCodec->name()
<< (ok ? "without" : "with") << "errors";
// emit signal on success
if (ok)
emit saved (filename);
// return success or not
return ok;
}