[Interest] QTextStream, QIODevice::Text and line endings convertation

Igor Mironchik igor.mironchik at gmail.com
Tue Nov 17 21:17:14 CET 2015


Hi,

In the following example:


#include <QCoreApplication>
#include <QTextStream>
#include <QDebug>

static const QChar c_n = QLatin1Char( '\n' );


QString readWord( QTextStream & stream )
{
     QChar ch;

     QString res;

     while( !stream.atEnd() )
     {
         stream >> ch;

         if( ch == c_n )
             break;
         else
             res.append( ch );
     }

     return res;
}


int main( int argc, char ** argv )
{
     QCoreApplication app( argc, argv );

     QString data = QLatin1String( "/*** Program Name ***/\r\n"
         "TEST PROGRAM TEST_00;\r\n"
         "BEGIN\r\n"
         "LOGIC\r\n"
         "NAME :\r"
         "ACTUAL_NAME\r\n"
         "OPTION ENABLE : " );

     QTextStream stream( &data, QIODevice::ReadOnly | QIODevice::Text );

     while( !stream.atEnd() )
     {
         qDebug() << readWord( stream );
     }

     return 0;
}

Line endings doesn't convert to \n as should be. On Windows with MSVC 
2013 if read that data from file then "NAME :\r" even doesn't recognize 
as line ending at all...

-- 
Best Regards,
Igor Mironchik.




More information about the Interest mailing list