
Originally Posted by
patrik08
now run

Yes, but IMO your first attempt was better (except for the bug).
I would implement it like this (not tested):
QString HTML_Edit
::file_get_line( const QString
& fullFileName,
int lineNr
) {
QFile file( fullFileName
);
int currentLineNr = 0; // or 1
while( ! in.atEnd() ) {
if( currentLineNr == lineNr ) {
result = line;
break;
}
currentLineNr += 1;
}
}
return result;
}
QString HTML_Edit::file_get_line( const QString& fullFileName, int lineNr )
{
QString result;
QFile file( fullFileName );
if( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
QTextStream in( &file );
int currentLineNr = 0; // or 1
while( ! in.atEnd() ) {
QString line( in.readLine() );
if( currentLineNr == lineNr ) {
result = line;
break;
}
currentLineNr += 1;
}
}
return result;
}
To copy to clipboard, switch view to plain text mode
Bookmarks