CanRead() and read()
-
could i suggest you, nokia's engeneers, to realize a method "read()" and a "canRead()". they are similar than "next()" and "hasNext()" of Java! =) they are for QFile (QFile::read() : QString and QFile::canRead() : QString)
what do you think about this, reader?
-
This is a community forum, so no garantee that nokia engeneers will read it.
What do you need these methods for? I think you are talking about language bindings to which language?
QFile (in C++ :-) ) already has a
- read()
- readLine()
- atEnd()
- readAll()
Why do you need additional functions?
-
spode, sorry, but what parameter are you talking about? readAll() doesn't have any parameters :)
-
And for what a method without parameter, just returning QString? This implies, QFile can only read text files, but it can access any type of file? That's why you get a byte array = data stream, not a QString.
Otherwise QFile must handle different types of text files (ASCII, Latin1, utf-8, utf-16, different encodings like greek, german, ...).
-
Actually, I did write some code that you can use to just read a string from the file system with a single method call. It even caches the reads. Very convenient, if you want to keep longer texts, HTML snippets or CSS in a resource file or elsewhere, and you just want to set their contents with a single line of code.
-
[quote author="spode" date="1306783216"]could i suggest you, nokia's engeneers, to realize a method "read()" and a "canRead()". they are similar than "next()" and "hasNext()" of Java! =) they are for QFile (QFile::read() : QString and QFile::canRead() : QString)
what do you think about this, reader?[/quote]
Java class File does neither have next() nor hasNext() methods.
What are you referring to?
-
i think it is wrong!
see here http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
@
File fileinp ( "prova.txt" );
if ( fileinp.canRead() )
{
System.out.println( fileinp.read() );
}
@it is easier to read from a file, verbatim! you need not to explain the max characters read() method can read and writing the source code is easier, as for me!
for Gerolf: i can not reply because i have not so much experience with Java...[EDIT: code formatting, please wrap in @-tags, Volker]
-
[quote author="spode" date="1306946648"]i think it is wrong!
see here http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
@
File fileinp ( "prova.txt" );
if ( fileinp.canRead() )
{
System.out.println( fileinp.read() );
}
@
[/quote]If java had a read() method on class File (but it does not have it!), then the equivalent code in Qt would be.
@
QFile fileinp("prova.txt");
QFileInfo fi(fileinp);
if(fi.isReadable()) {
qDebug() << fileinp.readAll();
}
@[quote author="spode" date="1306946648"]
it is easier to read from a file, verbatim! you need not to explain the max characters read() method can read and writing the source code is easier, as for me!
for Gerolf: i can not reply because i have not so much experience with Java...
[/quote]Sorry, I do not understand that sentence.
You still lack the explanation of "missing" next() or hasNext() methods.
-
Looks like what is needed for OP is QTextStream::operator>>(). It reads one word from QIODevice (where words are separeted with QChar::isSpace() chars).