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. Reading a file with Qt

Reading a file with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
35 Posts 10 Posters 6.3k 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.
  • E Offline
    E Offline
    EL-jos
    wrote on 2 Aug 2018, 20:50 last edited by
    #20

    Hey, everybody,

    Still in the example given by the Qt documentation for the exchange of large documents between the client and the server in a chatt software, I could separate the client and the server in different projects which is not the case in the example given by the Qt documentation.

    So here's my question:

    Just that there I do not know how to adapt this example to my chatt software to be able to send large files between client and server?

    Translated with www.DeepL.com/Translator

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Aug 2018, 21:03 last edited by
      #21

      There's nothing special to do, if you implement the client and the server the same way as the exemple, then it's also going to work the same.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EL-jos
        wrote on 2 Aug 2018, 21:43 last edited by
        #22

        Theoretically yes, but in practice this is not the case.

        M 1 Reply Last reply 2 Aug 2018, 22:11
        0
        • E EL-jos
          2 Aug 2018, 21:43

          Theoretically yes, but in practice this is not the case.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Aug 2018, 22:11 last edited by
          #23

          @EL-jos
          Hi
          As mr @Christian-Ehrlicher noted higher up.
          You are using quint16 for size handling
          Try
          #include <limits.h>
          qDebug() << std::numeric_limits<quint16>::max();

          and you will see the magic 65535 as maximum value.

          1 Reply Last reply
          2
          • E Offline
            E Offline
            EL-jos
            wrote on 3 Aug 2018, 04:34 last edited by
            #24

            Yes you are right but except that 65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo

            M J 2 Replies Last reply 3 Aug 2018, 04:39
            0
            • E EL-jos
              3 Aug 2018, 04:34

              Yes you are right but except that 65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Aug 2018, 04:39 last edited by
              #25

              @EL-jos
              then use quint64 instead.

              1 Reply Last reply
              5
              • E EL-jos
                3 Aug 2018, 04:34

                Yes you are right but except that 65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 3 Aug 2018, 04:40 last edited by JKSH 8 Mar 2018, 04:41
                #26

                @EL-jos said in Reading a file with Qt:

                65535 makes a maximum size of 64Ko or me I want to send voluminous documents of the order of 30Mo to even 50Mo

                Then you cannot use quint16. It is too small.

                Use quint32 or even quint64 instead.

                EDIT: @mrjj beat me to it!

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

                1 Reply Last reply
                5
                • E Offline
                  E Offline
                  EL-jos
                  wrote on 6 Aug 2018, 22:29 last edited by
                  #27

                  Hey, everybody.
                  I was able to solve my problem thanks to your advice, now I am able to send large document in my chatt software but there is a new problem that arises, here is the problem: Which class should I use to send a video file in my chatt software?
                  Example: for image exchange, I used the class QImage(Stream for image)but now what class used for Video(Stream video)?

                  J 1 Reply Last reply 7 Aug 2018, 04:55
                  0
                  • E EL-jos
                    6 Aug 2018, 22:29

                    Hey, everybody.
                    I was able to solve my problem thanks to your advice, now I am able to send large document in my chatt software but there is a new problem that arises, here is the problem: Which class should I use to send a video file in my chatt software?
                    Example: for image exchange, I used the class QImage(Stream for image)but now what class used for Video(Stream video)?

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 7 Aug 2018, 04:55 last edited by jsulm 8 Jul 2018, 04:56
                    #28

                    @EL-jos If it is a file then simply send the binary content of the file.
                    There is no need to use a dedicated class for each and every data type.
                    https://stackoverflow.com/questions/30288385/how-to-send-a-file-in-qt

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    3
                    • E Offline
                      E Offline
                      EL-jos
                      wrote on 7 Aug 2018, 22:48 last edited by
                      #29

                      Yes it is already what I do so I send data in bytes but except that it does not work because I have an error when reading my file like this file is not supported

                      J 1 Reply Last reply 8 Aug 2018, 06:11
                      0
                      • A Offline
                        A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on 8 Aug 2018, 05:58 last edited by
                        #30

                        @EL-jos

                        Why should a file not be supported if you just send it byte-by-byte? if you store it on a harddisk, it does not matter for the hard disk which file type it is. Its just a number of bytes.

                        Same happens when you send it over network.

                        Regards

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        1
                        • E EL-jos
                          7 Aug 2018, 22:48

                          Yes it is already what I do so I send data in bytes but except that it does not work because I have an error when reading my file like this file is not supported

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 8 Aug 2018, 06:11 last edited by
                          #31

                          @EL-jos said in Reading a file with Qt:

                          error when reading my file like this file is not supported

                          Please explain. Where do you get this error? QFile (I guess you use it for reading) does not care at all about file content.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • E Offline
                            E Offline
                            EL-jos
                            wrote on 8 Aug 2018, 06:52 last edited by
                            #32

                            In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported

                            J J 2 Replies Last reply 8 Aug 2018, 07:05
                            0
                            • E EL-jos
                              8 Aug 2018, 06:52

                              In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 8 Aug 2018, 07:05 last edited by
                              #33

                              @EL-jos You should show how you receive the data (whole code not just a small part of it).

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • E EL-jos
                                8 Aug 2018, 06:52

                                In fact after the client sends the byte array, the server receives the bytes and Opens a file in write only mode and writes all the bytes received but except that if I try via VLC to read this file, there is a message that appears like this file is not supported

                                J Offline
                                J Offline
                                JonB
                                wrote on 8 Aug 2018, 07:06 last edited by
                                #34

                                @EL-jos
                                So you need to do a little detective work to help yourself.

                                You have a file which is openable by "VLC" (whatever that is) at the client before you start, right? And you're saying after you have sent it to server it is not openable, right?

                                So start by using a regular file copy, outside of anything Qt, to copy the file from client to server. Make sure you keep the same filename extension. Then: Is the copied file openable on the server? Is it the same size as when you copy via Qt? Use a file content comparison tool (e.g. Windows fc /b), is the file content of the Qt copy identical to that of the non-Qt copy?

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  EL-jos
                                  wrote on 8 Aug 2018, 07:12 last edited by
                                  #35

                                  Okay I'll try to put your advice into practice then find my mistake if I still can't I'll have to post my code for you to see it

                                  1 Reply Last reply
                                  0

                                  29/35

                                  7 Aug 2018, 22:48

                                  • Login

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