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

Reading a file with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
35 Posts 10 Posters 6.8k Views 4 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.
  • E Offline
    E Offline
    EL-jos
    wrote on last edited by
    #11

    Yes I have this problem because I noticed that if my file size is larger than 65535 bytes, the server does not receive all the information. But how do we solve this problem?

    Then if I use Qdatastream this to first write the identifier of my message because the one that says if it is a text message (5), if it is a new connection (3), if it is a disconnect (4) and for the file the identifier value is (7) to tell the server that it is a file. Here the QDATASTREAM allows me to write a screen like this:

    *Message size

    *Identifier

    *Message

    So if I don't use a Qdatastream how can I write in my QByteArray?

    Translated with www.DeepL.com/Translator

    aha_1980A 1 Reply Last reply
    0
    • E EL-jos

      Yes I have this problem because I noticed that if my file size is larger than 65535 bytes, the server does not receive all the information. But how do we solve this problem?

      Then if I use Qdatastream this to first write the identifier of my message because the one that says if it is a text message (5), if it is a new connection (3), if it is a disconnect (4) and for the file the identifier value is (7) to tell the server that it is a file. Here the QDATASTREAM allows me to write a screen like this:

      *Message size

      *Identifier

      *Message

      So if I don't use a Qdatastream how can I write in my QByteArray?

      Translated with www.DeepL.com/Translator

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #12

      Hi @EL-jos,

      What do you want to do exactly?

      For file transfer, decicated protocols exists, e.g. FTP or HTTP. To me it looks like your are re-inventing the wheel?

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EL-jos
        wrote on last edited by EL-jos
        #13

        Concretely I want my client to send a file to my server and the server after receiving the file, that it sends this file to all the client that are connected to it.
        Because it is a chat software then I also want the client to be able to send a file to another client via a server.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Please take a look at the examples (again...) how to send large data ... http://doc.qt.io/qt-5/qtnetwork-loopback-example.html

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • E Offline
            E Offline
            EL-jos
            wrote on last edited by
            #15

            Okay Thanks, I'll read this example and then I'll come back to you to give you the follow-up.

            Thank you

            1 Reply Last reply
            0
            • E Offline
              E Offline
              EL-jos
              wrote on last edited by
              #16

              Hi,
              after several studies of the example given by the Qt documentation, I don't know where and how to send my file to the server?

              then in the example given by the Qt documentation, just sends the same 64KB packet several times until it tints 50MB . and the server and the client are in the same project but in my case the client and the server are different projects

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #17

                Hi,

                Are you writing both the client and server parts ?

                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 last edited by
                  #18

                  Yes, do you want me to mail them?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    It was regarding your last remark about the server and client being in the same project. Since you are writing both, then it doesn't matter that they are in different projects.

                    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
                    1
                    • E Offline
                      E Offline
                      EL-jos
                      wrote on 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
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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 last edited by
                          #22

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

                          mrjjM 1 Reply Last reply
                          0
                          • E EL-jos

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

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 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 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

                              mrjjM JKSHJ 2 Replies Last reply
                              0
                              • E EL-jos

                                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

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #25

                                @EL-jos
                                then use quint64 instead.

                                1 Reply Last reply
                                5
                                • E EL-jos

                                  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

                                  JKSHJ Offline
                                  JKSHJ Offline
                                  JKSH
                                  Moderators
                                  wrote on last edited by JKSH
                                  #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 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)?

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • E EL-jos

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

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by jsulm
                                      #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 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

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • aha_1980A Offline
                                          aha_1980A Offline
                                          aha_1980
                                          Lifetime Qt Champion
                                          wrote on 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

                                          • Login

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