本文整理汇总了C++中QTextStream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::read方法的具体用法?C++ QTextStream::read怎么用?C++ QTextStream::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rewriteDetailsForLocation
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
QmlJS::Document::Ptr doc, int requestId, const QmlDebug::QmlEventLocation &location)
{
PropertyVisitor propertyVisitor;
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);
if (!node)
return;
qint64 startPos = node->firstSourceLocation().begin();
qint64 len = node->lastSourceLocation().end() - startPos;
textDoc.seek(startPos);
QString details = textDoc.read(len).replace(QLatin1Char('\n'), QLatin1Char(' ')).simplified();
emit rewriteDetailsString(requestId, details);
}
示例2: load
// ---------------------------------------------------
bool TextDoc::load ()
{
QFile file (DocName);
if (!file.open (QIODevice::ReadOnly))
return false;
setLanguage (DocName);
QTextStream stream (&file);
setText (stream.read ());
setModified (false);
slotSetChanged ();
file.close ();
lastSaved = QDateTime::currentDateTime ();
loadSettings ();
SimOpenDpl = simulation ? true : false;
return true;
}
示例3: 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
}
示例4: parse
bool CSVParser::parse(QTextStream& stream, qint64 nMaxRecords)
{
m_vCSVData.clear();
m_nColumns = 0;
ParseStates state = StateNormal;
QString fieldbuf;
QStringList record;
if(m_pCSVProgress)
m_pCSVProgress->start();
while(!stream.atEnd())
{
QString sBuffer = stream.read(m_nBufferSize);
for(QString::iterator it = sBuffer.begin(); it != sBuffer.end(); ++it)
{
QChar c = *it;
switch(state)
{
case StateNormal:
{
if(c == m_cFieldSeparator)
{
addColumn(record, fieldbuf, m_bTrimFields);
}
else if(c == m_cQuoteChar)
{
state = StateInQuote;
}
else if(c == '\r')
{
// look ahead to check for linefeed
QString::iterator nit = it + 1;
// In order to check what the next byte is we must make sure that that byte is already loaded. Assume we're at an m_nBufferSize
// boundary but not at the end of the file when we hit a \r character. Now we're going to be at the end of the sBuffer string
// because of the m_nBufferSize boundary. But this means that the following check won't work properly because we can't check the
// next byte when we really should be able to do so because there's more data coming. To fix this we'll check for this particular
// case and, if this is what's happening, we'll just load an extra byte.
if(nit == sBuffer.end() && !stream.atEnd())
{
// Load one more byte
sBuffer.append(stream.read(1));
// Restore both iterators. sBuffer.end() points to the imagined char after the last one in the string. So the extra byte we've
// just loaded is the one before that, i.e. the actual last one, and the original last char is the one before that.
it = sBuffer.end() - 2;
nit = sBuffer.end() - 1;
}
// no linefeed, so assume that CR represents a newline
if(nit != sBuffer.end() && *nit != '\n')
{
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
}
else if(c == '\n')
{
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
else
{
fieldbuf.append(c);
}
}
break;
case StateInQuote:
{
if(c == m_cQuoteChar)
{
state = StateEndQuote;
}
else
{
fieldbuf.append(c);
}
}
break;
case StateEndQuote:
{
if(c == m_cQuoteChar)
{
state = StateInQuote;
fieldbuf.append(c);
}
else if(c == m_cFieldSeparator)
{
state = StateNormal;
addColumn(record, fieldbuf, m_bTrimFields);
}
else if(c == '\n')
{
state = StateNormal;
addColumn(record, fieldbuf, m_bTrimFields);
//.........这里部分代码省略.........
示例5: 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();
}
示例6: getProcApmStatusIpaq
/*
* Make use of the advanced apm interface of the ipaq
*/
bool BatteryStatus::getProcApmStatusIpaq() {
bat2 = false;
QFile procApmIpaq("/proc/hal/battery");
if (procApmIpaq.open(IO_ReadOnly) ) {
QStringList list;
// since it is /proc we _must_ use QTextStream
QTextStream stream ( &procApmIpaq);
QString streamIn;
streamIn = stream.read();
list = QStringList::split("\n", streamIn);
sec2 = sec1 = "";
for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
// not nice, need a rewrite later
if( (*line).startsWith(" Percentage") ) {
if (bat2 == true) {
perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
} else {
perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
}
} else if( (*line).startsWith(" Life") ) {
if (bat2 == true) {
sec2 = (*line).mid(((*line).find(':')+2), 5 );
} else {
sec1 = (*line).mid(((*line).find(':')+2), 5 );
}
} else if( (*line).startsWith("Battery #1") ) {
bat2 = true;
} else if( (*line).startsWith(" Status") ) {
if (bat2 == true) {
jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
} else {
ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
}
} else if( (*line).startsWith(" Chemistry") ) {
if (bat2 == true) {
jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
} else {
ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
}
}
}
procApmIpaq.close();
}
jackPercent = perc2.toInt();
ipaqPercent = perc1.toInt();
if (perc2.isEmpty() || perc2 == "unknown" ) {
perc2 = tr("no data");
} else {
perc2 += " %";
}
if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
sec2 = tr("no data");
} else {
sec2 += " min";
}
jackStatus.prepend( " ( " );
jackStatus.append( " )" );
return true;
}