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()
Forum Updated to NodeBB v4.3 + New Features

CanRead() and read()

Scheduled Pinned Locked Moved Brainstorm
14 Posts 5 Posters 6.0k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DenisKormalev
    wrote on 30 May 2011, 22:29 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 31 May 2011, 05:37 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 31 May 2011, 05:40 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 31 May 2011, 10:20 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 1 Jun 2011, 16:44 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 1 Jun 2011, 17:19 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 1 Jun 2011, 17:23 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 1 Jun 2011, 17:25 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 1 Jun 2011, 17:39 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 1 Jun 2011, 17:40 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 4 Jun 2011, 16:21 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

                        13/14

                        1 Jun 2011, 17:40

                        • Login

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