本文整理汇总了C++中QTextStream::setEncoding方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::setEncoding方法的具体用法?C++ QTextStream::setEncoding怎么用?C++ QTextStream::setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::setEncoding方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startDoxyAnchor
void ManGenerator::startDoxyAnchor(const char *,const char *manName,
const char *, const char *name,
const char *)
{
// something to be done?
if( !Config_getBool("MAN_LINKS") )
{
return; // no
}
// the name of the link file is derived from the name of the anchor:
// - truncate after an (optional) ::
QCString baseName = name;
int i=baseName.findRev(':');
if (i!=-1) baseName=baseName.right(baseName.length()-i-1);
// - remove dangerous characters and append suffix, then add dir prefix
QCString fileName=dir+"/"+buildFileName( baseName );
QFile linkfile( fileName );
// - only create file if it doesn't exist already
if ( !linkfile.open( IO_ReadOnly ) )
{
if ( linkfile.open( IO_WriteOnly ) )
{
QTextStream linkstream;
linkstream.setDevice(&linkfile);
#if QT_VERSION >= 200
linkstream.setEncoding(QTextStream::Latin1);
#endif
linkstream << ".so man" << getExtension() << "/" << buildFileName( manName ) << endl;
}
}
linkfile.close();
}
示例2: GetValidXML
void UPnpDeviceDesc::GetValidXML(
const QString &sBaseAddress, int nPort,
QTextStream &os, const QString &sUserAgent )
{
#if 0
os.setEncoding( QTextStream::UnicodeUTF8 );
#endif
QString BaseAddr;
QHostAddress addr(sBaseAddress);
BaseAddr = sBaseAddress;
#if !defined(QT_NO_IPV6)
// Basically if it appears to be an IPv6 IP surround the IP with []
// otherwise don't bother
if (sBaseAddress.contains(":"))
BaseAddr = "[" + sBaseAddress + "]";
#endif
os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
" xmlns:mythtv=\"mythtv.org\">\n"
"<specVersion>\n"
"<major>1</major>\n"
"<minor>0</minor>\n"
"</specVersion>\n"
"<URLBase>http://"
<< BaseAddr << ":" << nPort << "/</URLBase>\n";
OutputDevice( os, &m_rootDevice, sUserAgent );
os << "</root>\n";
os << flush;
}
示例3: WriteConfigFile
//
// Write the data configuration element to the XML output stream. Call
// the appropriate configuration type-specific private function to actually
// perform the writing.
//
bool CDCConfig::WriteConfigFile(wchar_t *configFileName)
{
QFile* pFile = NULL ;
QTextStream xmlStream ;
if (m_configType == DCConfigInvalid) {
// No valid configuration data
return( false ) ;
}
pFile = new QFile( QString::fromUcs2((const short unsigned int*)configFileName) ) ;
if (! pFile->open( QIODevice::WriteOnly )) {
// Fill open error
return( false ) ;
}
xmlStream.setDevice( pFile ) ;
// Set XML file character encoding
xmlStream.setEncoding(QTextStream::UnicodeUTF8) ;
// xmlStream.setEncoding(QTextStream::Unicode) ;
xmlStream << "<?xml version=\"1.0\"?>\n" ;
xmlStream << "<!DOCTYPE dc_configuration SYSTEM \"dcconfig.dtd\">\n";
xmlStream << "<dc_configuration" ;
if (m_cpuType.isEmpty())
m_cpuType = getCurrentCpuType();
WriteStringAttr(xmlStream, "cpu_type", m_cpuType) ;
xmlStream << ">\n" ;
switch( m_configType ) {
case DCConfigTBP:
{
WriteTBP( xmlStream ) ;
break ;
}
case DCConfigEBP:
{
WriteEBP( xmlStream ) ;
break ;
}
case DCConfigTBPPerf:
{
WriteTBPPerf( xmlStream ) ;
break ;
}
default:
break;
}
xmlStream << "</dc_configuration>\n" ;
// Close file and deallocate QFile explicitly
xmlStream.unsetDevice() ;
pFile->close() ;
delete pFile ;
return( true ) ;
}
示例4: save
void HighlightConfig::save()
{
QString fileName = locateLocal( "appdata", QString::fromLatin1( "highlight.xml" ) );
KSaveFile file( fileName );
if( file.status() == 0 )
{
QTextStream *stream = file.textStream();
stream->setEncoding( QTextStream::UnicodeUTF8 );
QString xml = QString::fromLatin1(
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE kopete-highlight-plugin>\n"
"<highlight-plugin>\n" );
// Save metafilter information.
QPtrListIterator<Filter> filtreIt( m_filters );
for( ; filtreIt.current(); ++filtreIt )
{
Filter *filtre = *filtreIt;
xml += QString::fromLatin1( " <filter>\n <display-name>" )
+ QStyleSheet::escape(filtre->displayName)
+ QString::fromLatin1( "</display-name>\n" );
xml += QString::fromLatin1(" <search caseSensitive=\"") + QString::number( static_cast<int>( filtre->caseSensitive ) ) +
QString::fromLatin1("\" regExp=\"") + QString::number( static_cast<int>( filtre->isRegExp ) ) +
QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->search ) + QString::fromLatin1( "</search>\n" );
xml += QString::fromLatin1(" <BG set=\"") + QString::number( static_cast<int>( filtre->setBG ) ) +
QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->BG.name() ) + QString::fromLatin1( "</BG>\n" );
xml += QString::fromLatin1(" <FG set=\"") + QString::number( static_cast<int>( filtre->setFG ) ) +
QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->FG.name() ) + QString::fromLatin1( "</FG>\n" );
xml += QString::fromLatin1(" <importance set=\"") + QString::number( static_cast<int>( filtre->setImportance ) ) +
QString::fromLatin1( "\">" ) + QString::number( filtre->importance ) + QString::fromLatin1( "</importance>\n" );
xml += QString::fromLatin1(" <sound set=\"") + QString::number( static_cast<int>( filtre->playSound ) ) +
QString::fromLatin1( "\">" ) + QStyleSheet::escape( filtre->soundFN ) + QString::fromLatin1( "</sound>\n" );
xml += QString::fromLatin1(" <raise set=\"") + QString::number( static_cast<int>( filtre->raiseView ) ) +
QString::fromLatin1( "\"></raise>\n" );
xml += QString::fromLatin1( " </filter>\n" );
}
xml += QString::fromLatin1( "</highlight-plugin>\n" );
*stream << xml;
}
}
示例5: 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);
}
示例6: GetValidXML
void UPnpDeviceDesc::GetValidXML(
const QString &/*sBaseAddress*/, int /*nPort*/,
QTextStream &os, const QString &sUserAgent )
{
#if 0
os.setEncoding( QTextStream::UnicodeUTF8 );
#endif
os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
" xmlns:mythtv=\"mythtv.org\">\n"
"<specVersion>\n"
"<major>1</major>\n"
"<minor>0</minor>\n"
"</specVersion>\n";
OutputDevice( os, &m_rootDevice, sUserAgent );
os << "</root>\n";
os << flush;
}
示例7: doc
FLTableMetaData *FLManager::createSystemTable(const QString &n)
{
#ifndef FL_QUICK_CLIENT
if (!existsTable(n)) {
QDomDocument doc(n);
QDomElement docElem;
QFile fi(AQ_DATA +
QString::fromLatin1("/tables/") + n +
QString::fromLatin1(".mtd"));
if (!fi.open(IO_ReadOnly)) {
#ifdef FL_DEBUG
qWarning("FLManager : " + QApplication::tr("Los metadatos para %1 no están definidos").arg(n));
#endif
} else {
QTextStream t;
t.setDevice(&fi);
t.setEncoding(QTextStream::Latin1);
QString stream = t.read();
if (!FLUtil::domDocumentSetContent(doc, stream)) {
#ifdef FL_DEBUG
qWarning("FLManager::createSystemTable : " + QApplication::tr("Error al cargar los metadatos para la tabla %1").arg(n));
#endif
return 0;
} else {
docElem = doc.documentElement();
FLTableMetaData *mtd = createTable(metadata(&docElem, true));
return mtd;
}
}
fi.close();
}
return 0;
#else
return metadata(n, true);
#endif //FL_QUICK_CLIENT
}
示例8: taskFinished
void VCardFactory::taskFinished()
{
JT_VCard *task = (JT_VCard *)sender();
if ( task->success() ) {
Jid j = task->jid();
VCard *vcard = new VCard;
*vcard = task->vcard();
checkLimit(j.userHost(), vcard);
// save vCard to disk
QFile file ( vCardsDir_ + "/" + JIDUtil::encode(j.userHost()).lower() + ".xml" );
file.open ( QIODevice::WriteOnly );
QTextStream out ( &file );
out.setEncoding ( QTextStream::UnicodeUTF8 );
QDomDocument doc;
doc.appendChild( vcard->toXml ( &doc ) );
out << doc.toString(4);
emit vcardChanged(j);
}
}
示例9: update
/*! This function updates .ini file in two stages. It copies original .ini file
into temporary one line by line, replacing/deleting/adding lines as necessary.
Then it copies temporary file into original one and deletes temporary file.
*/
bool TEIniFile::update()
{
close();
if (!f.open(IO_ReadWrite)) return false;
QString tempfn=f.name()+".tmp";
QFile tempf(tempfn);
if (!tempf.open(IO_ReadWrite | IO_Truncate)) return false;
QTextStream tsorg;
bool skipsec=false;
tsorg.setEncoding(QTextStream::UnicodeUTF8);
tsorg.setDevice(&f);
ts.setDevice(&tempf); // writeXXX function hardwired to write into ts. So we set it appropriatedly.
// prepare
QMap<QString,bool> secProcd, valueProcd; // processedp flag's maps
QMapIterator<QString,type_ValueList> it1;
for(it1=SectionList.begin();it1!=SectionList.end();++it1)
{
secProcd[it1.key()]=false;
}
// scan form sections
QString line, sec;
type_Processing pr = P_NONE; // nothing done yet
type_ValueList ValueList;
while (!((line = tsorg.readLine()).isNull())) {
if ((pr == P_NONE) || (pr == P_SECTION)) {
// trim line
line = line.stripWhiteSpace();
// skip if empty
if (line.isEmpty())
{
writeBreak();
continue;
}
// skip if comment
if (line.startsWith("#"))
{
writeComment(line.mid(1));
continue;
}
// check if section
if (line.startsWith("[") && line.endsWith("]")) {
if (pr == P_SECTION) {
// update previous section
// write new values
type_ValueList::iterator it;
type_ValueList & curSec=SectionList[sec];
type_ValueList & curSecDef=SectionListDef[sec];
for(it=curSec.begin();it!=curSec.end();++it)
{
if (!valueProcd[it.key()])
{ // this value was not processed yet, hence it's new or just default.
if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data()) // if it equals default value, skip it.
ts << it.key() << "\t" << it.data() << "\n";
valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?).
}
}
secProcd[sec]=true;
}
// section found!
valueProcd.clear(); // get ready for next section
pr = P_SECTION;
sec = line.mid(1, line.length()-2).stripWhiteSpace();
writeSection(sec);
skipsec=SectionList.find(sec)==SectionList.end() || secProcd[sec]==true; // Skip deleted or already processed section
type_ValueList & curSec=SectionList[sec];
type_ValueList::iterator it;
for(it=curSec.begin();it!=curSec.end();++it)
{
valueProcd[it.key()]=false;
}
ValueList.clear();
continue;
}
if (pr == P_SECTION) {
// read name
if (skipsec)
continue;
QString nam;
int j = 0, l = (int)line.length();
QChar c;
while ( (j < l) && !((c = line.ref((uint)j)).isSpace()) ) {
nam += c;
j++;
}
// read value
bool rawData=false;
bool doubleQuotes=false;
QString val;
val = line.mid((uint)j).stripWhiteSpace();
if (val == "data{") {
rawData=true;
// read raw data...
val = "";
while (!((line = ts.readLine()).isNull())) {
//.........这里部分代码省略.........
示例10: if
bool K3bCddbQuery::parseEntry( QTextStream& stream, K3bCddbResultEntry& entry )
{
entry.rawData = "";
stream.setEncoding( QTextStream::UnicodeUTF8 );
// parse data
QString line;
while( !(line = stream.readLine()).isNull() ) {
entry.rawData.append(line + "\n");
// !all fields may be splitted into several lines!
if( line.startsWith( "DISCID" ) ) {
// TODO: this could be several discids separated by comma!
}
else if( line.startsWith( "DYEAR" ) ) {
QString year = line.mid( 6 );
if( year.length() == 4 )
entry.year = year.toInt();
}
else if( line.startsWith( "DGENRE" ) ) {
entry.genre = line.mid( 7 );
}
else if( line.startsWith( "DTITLE" ) ) {
entry.cdTitle += line.mid( 7 );
}
else if( line.startsWith( "TTITLE" ) ) {
int eqSgnPos = line.find( "=" );
bool ok;
uint trackNum = (uint)line.mid( 6, eqSgnPos - 6 ).toInt( &ok );
if( !ok )
kdDebug() << "(K3bCddbQuery) !!! PARSE ERROR: " << line << endl;
else {
// kdDebug() << "(K3bCddbQuery) Track title for track " << trackNum << endl;
// make sure the list is big enough
while( entry.titles.count() <= trackNum )
entry.titles.append( "" );
entry.titles[trackNum] += line.mid( eqSgnPos+1 );
}
}
else if( line.startsWith( "EXTD" ) ) {
entry.cdExtInfo += line.mid( 5 );
}
else if( line.startsWith( "EXTT" ) ) {
int eqSgnPos = line.find( "=" );
bool ok;
uint trackNum = (uint)line.mid( 4, eqSgnPos - 4 ).toInt( &ok );
if( !ok )
kdDebug() << "(K3bCddbQuery) !!! PARSE ERROR: " << line << endl;
else {
// kdDebug() << "(K3bCddbQuery) Track extr track " << trackNum << endl;
// make sure the list is big enough
while( entry.extInfos.count() <= trackNum )
entry.extInfos.append( "" );
entry.extInfos[trackNum] += line.mid( eqSgnPos+1 );
}
}
else if( line.startsWith( "#" ) ) {
// kdDebug() << "(K3bCddbQuery) comment: " << line << endl;
}
else {
kdDebug() << "(K3bCddbQuery) Unknown field: " << line << endl;
}
}
// now split the titles in the last added match
// if no " / " delimiter is present title and artist are the same
// -------------------------------------------------------------------
QString fullTitle = entry.cdTitle;
int splitPos = fullTitle.find( " / " );
if( splitPos < 0 )
entry.cdArtist = fullTitle;
else {
// split
entry.cdTitle = fullTitle.mid( splitPos + 3 );
entry.cdArtist = fullTitle.left( splitPos );
}
for( QStringList::iterator it = entry.titles.begin();
it != entry.titles.end(); ++it ) {
QString fullTitle = *it;
int splitPos = fullTitle.find( " / " );
if( splitPos < 0 )
entry.artists.append( entry.cdArtist );
else {
// split
//.........这里部分代码省略.........
示例11: logFile
void
CollectionScanner::doJob() //SLOT
{
std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
std::cout << "<scanner>";
QStringList entries;
if( m_restart ) {
QFile logFile( m_logfile );
QString lastFile;
if ( !logFile.open( IO_ReadOnly ) )
warning() << "Failed to open log file " << logFile.name() << " read-only"
<< endl;
else {
QTextStream logStream;
logStream.setDevice(&logFile);
logStream.setEncoding(QTextStream::UnicodeUTF8);
lastFile = logStream.read();
logFile.close();
}
QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files" );
if ( !folderFile.open( IO_ReadOnly ) )
warning() << "Failed to open folder file " << folderFile.name()
<< " read-only" << endl;
else {
QTextStream folderStream;
folderStream.setDevice(&folderFile);
folderStream.setEncoding(QTextStream::UnicodeUTF8);
entries = QStringList::split( "\n", folderStream.read() );
}
for( int count = entries.findIndex( lastFile ) + 1; count; --count )
entries.pop_front();
}
else {
foreachType( QStringList, m_folders ) {
if( (*it).isEmpty() )
//apparently somewhere empty strings get into the mix
//which results in a full-system scan! Which we can't allow
continue;
QString dir = *it;
if( !dir.endsWith( "/" ) )
dir += '/';
readDir( dir, entries );
}
QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files" );
if ( !folderFile.open( IO_WriteOnly ) )
warning() << "Failed to open folder file " << folderFile.name()
<< " read-only" << endl;
else {
QTextStream stream( &folderFile );
stream.setEncoding(QTextStream::UnicodeUTF8);
stream << entries.join( "\n" );
folderFile.close();
}
}
if( !entries.isEmpty() ) {
if( !m_restart ) {
AttributeMap attributes;
attributes["count"] = QString::number( entries.count() );
writeElement( "itemcount", attributes );
}
scanFiles( entries );
}
std::cout << "</scanner>" << std::endl;
quit();
}