Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. CanRead() and read()

CanRead() and read()

Scheduled Pinned Locked Moved Brainstorm
14 Posts 5 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

        yes, i know. these methods makes sure to have an explicit paramether...and i need a method with no paramether...like Java!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          spode, sorry, but what parameter are you talking about? readAll() doesn't have any parameters :)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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, ...).

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                [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?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  spode
                  wrote on last edited by
                  #8

                  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]

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [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.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      spode
                      wrote on last edited by
                      #10

                      0k, if you just want all the text. but if you need only a word?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        Then write a parser or split the string (you will find the relevant methods with a quick search in Assinstant or Creator's help). It depends on your definition of word boundaries.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          spode
                          wrote on last edited by
                          #12

                          yes, i know. i say that is more difficult than Java's methos...

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #13

                            You still lack explanations or examples of what your talking about. Up to now it just reads like silly trolling....

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DenisKormalev
                              wrote on last edited by
                              #14

                              Looks like what is needed for OP is QTextStream::operator>>(). It reads one word from QIODevice (where words are separeted with QChar::isSpace() chars).

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved