Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make QFile read the whole line
Forum Updated to NodeBB v4.3 + New Features

How to make QFile read the whole line

Scheduled Pinned Locked Moved Unsolved General and Desktop
48 Posts 8 Posters 9.2k Views 2 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.
  • ManiRonM ManiRon

    @Christian-Ehrlicher

    ok sir, But i tried to write the data what ever i stored in a QBytearray to another file and the result was same . Thats why i concluded that QByteArray terminate at NUL and its mentioned
    here
    http://doc.qt.io/qt-5/qbytearray.html#details

    J.HilkJ Online
    J.HilkJ Online
    J.Hilk
    Moderators
    wrote on last edited by J.Hilk
    #38

    @ManiRon said in How to make QFile read the whole line:

    @Christian-Ehrlicher

    ok sir, But i tried to write the data what ever i stored in a QBytearray to another file and the result was same . Thats why i concluded that QByteArray terminate at NUL and its mentioned
    here
    http://doc.qt.io/qt-5/qbytearray.html#details

    where exactly ?
    because the docu clearly sates otherwise and, thats in the section you linked!

    ->
    0_1542352803222_1ca28d44-9917-4c44-89dc-0ae3b23ac891-image.png


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    ManiRonM 1 Reply Last reply
    2
    • J.HilkJ J.Hilk

      @ManiRon said in How to make QFile read the whole line:

      @Christian-Ehrlicher

      ok sir, But i tried to write the data what ever i stored in a QBytearray to another file and the result was same . Thats why i concluded that QByteArray terminate at NUL and its mentioned
      here
      http://doc.qt.io/qt-5/qbytearray.html#details

      where exactly ?
      because the docu clearly sates otherwise and, thats in the section you linked!

      ->
      0_1542352803222_1ca28d44-9917-4c44-89dc-0ae3b23ac891-image.png

      ManiRonM Offline
      ManiRonM Offline
      ManiRon
      wrote on last edited by
      #39

      @J.Hilk 0_1542353448743_Capture.JPG

      In this line its mentioned

      JonBJ 1 Reply Last reply
      0
      • ManiRonM ManiRon

        @J.Hilk 0_1542353448743_Capture.JPG

        In this line its mentioned

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #40

        @ManiRon
        What is mentioned?? Oh dear! If you read, that is talking about it is an extra '\0'/NUL byte terminator which QByteArray chooses to store at the end of whatever data you have asked it to store. It has nothing to do with any NUL byte you have in your actual data. So far as you/your code is concerned, simply 100% ignore this extra byte, you won't see it and it won't affect you.

        Because your data is not a NUL terminated string, but rather arbitrary bytes of data, make sure anything you copy into to/out of a QByteArray always specifies the size/number of bytes you want copied, and does not use a call which says it terminates at a NUL/treats it like a string.

        For example, say you have your data in a char[], or similar. You would want to use http://doc.qt.io/qt-5/qbytearray.html#QByteArray-1

        QByteArray::QByteArray(const char *data, int size = -1)

        However, you must not fail to pass in size and allow that to take its default value of -1. If you do that, it will only copy up to wherever the first NUL byte happens to sit in your data buffer. That is not what you want (assuming you want to copy everything). In your case you must explicitly pass the desired number of bytes to copy as size, then it will copy all your embedded NUL bytes too.

        And please wherever you do use qDebug() to see what's going on, follow the link I gave you https://www.qtcentre.org/threads/54236-qDebug-donsn-t-display-0x00?p=243053#post243053 where it suggests you use:

        qDebug() << yourQByteArrayVariable.toHex();
        

        See that .toHex() at the end?

        1 Reply Last reply
        4
        • J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #41

          @JonB I agree with your points, but did you see the op apparently calls toHex on his byteArray

          https://forum.qt.io/topic/96627/how-to-make-qfile-read-the-whole-line/9

          but maybe at the wrong place, it's after QCryptographicHash is done with it.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ ManiRonM 2 Replies Last reply
          0
          • J.HilkJ J.Hilk

            @JonB I agree with your points, but did you see the op apparently calls toHex on his byteArray

            https://forum.qt.io/topic/96627/how-to-make-qfile-read-the-whole-line/9

            but maybe at the wrong place, it's after QCryptographicHash is done with it.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #42

            @J.Hilk , @ManiRon
            so the OP needs to

            • Display the length/hex representation of fileData.data() before calling QCryptographicHash::hash.
            • Display the length/hex representation of FileHashData after calling QCryptographicHash::hash.
            • How do we know the output from
                FileHashData= QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
                qDebug() << FileHashData.toHex();
            

            is actually "wrong"? I haven't seen that. Is it shorter than the input? Do we have any reason to presume that QCryptographicHash::hash(fileData, QCryptographicHash::Md5) output must be shorter/same length/longer than its input?

            Hang on: he's outputting FileHashData.toHex();. But don't you have to use http://doc.qt.io/qt-5/qcryptographichash.html#result to get the result, no? I've never used any of these functions, so how would I know, but I make the effort to read the docs. Can the OP do that himself?

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @JonB I agree with your points, but did you see the op apparently calls toHex on his byteArray

              https://forum.qt.io/topic/96627/how-to-make-qfile-read-the-whole-line/9

              but maybe at the wrong place, it's after QCryptographicHash is done with it.

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by ManiRon
              #43

              @J.Hilk

              Sir, Actually i am in a confusion . Now i checked in different mannerwith the QByteArray but it had all the read data . But in qDebug it showed the data till the NUL is accomplished . I tried printing the data char by char till the whole size of file and i was able to see that the QByteArray variable had the whole data . So i think it maybe the qDebug problem as you guys mentioned . But my another doubt is if the QByteArray has all the data when i wrote the same data in file why it didnt write and why it wrote till first NUL?

              JonBJ JKSHJ 2 Replies Last reply
              0
              • ManiRonM ManiRon

                @J.Hilk

                Sir, Actually i am in a confusion . Now i checked in different mannerwith the QByteArray but it had all the read data . But in qDebug it showed the data till the NUL is accomplished . I tried printing the data char by char till the whole size of file and i was able to see that the QByteArray variable had the whole data . So i think it maybe the qDebug problem as you guys mentioned . But my another doubt is if the QByteArray has all the data when i wrote the same data in file why it didnt write and why it wrote till first NUL?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #44

                @ManiRon

                But in qDebug it showed the data till the NUL is accomplished . I tried printing the data char by char till the whole size of file and i was able to see that the QByteArray variable had the whole data .

                I give up. How many times can one say that qDebug() << QByteArray will stop at NUL so not to use it?

                ManiRonM 1 Reply Last reply
                2
                • JonBJ JonB

                  @ManiRon

                  But in qDebug it showed the data till the NUL is accomplished . I tried printing the data char by char till the whole size of file and i was able to see that the QByteArray variable had the whole data .

                  I give up. How many times can one say that qDebug() << QByteArray will stop at NUL so not to use it?

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by ManiRon
                  #45

                  @JonB

                  oh ok sir. But if that is the case it should stop when i try to print it using a char by char right? Just a doubt sir?

                  JonBJ 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @JonB

                    oh ok sir. But if that is the case it should stop when i try to print it using a char by char right? Just a doubt sir?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #46

                    @ManiRon
                    I'm sorry but I cannot find anyway to explain and answer your questions any longer. Maybe someone else can explain better than I to you.

                    I would however suggest that you/someone look at what I said above about http://doc.qt.io/qt-5/qcryptographichash.html#result and see whether you need to be using that to get your hash result.

                    ManiRonM 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @ManiRon
                      I'm sorry but I cannot find anyway to explain and answer your questions any longer. Maybe someone else can explain better than I to you.

                      I would however suggest that you/someone look at what I said above about http://doc.qt.io/qt-5/qcryptographichash.html#result and see whether you need to be using that to get your hash result.

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by
                      #47

                      @JonB no sir i can understand what u are trying to explain . dont mistake me

                      1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @J.Hilk

                        Sir, Actually i am in a confusion . Now i checked in different mannerwith the QByteArray but it had all the read data . But in qDebug it showed the data till the NUL is accomplished . I tried printing the data char by char till the whole size of file and i was able to see that the QByteArray variable had the whole data . So i think it maybe the qDebug problem as you guys mentioned . But my another doubt is if the QByteArray has all the data when i wrote the same data in file why it didnt write and why it wrote till first NUL?

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #48

                        @ManiRon said in How to make QFile read the whole line:

                        if the QByteArray has all the data when i wrote the same data in file why it didnt write and why it wrote till first NUL?

                        Show us how you wrote the data to the file.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        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