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. QFile Read Binary blockwise
Forum Update on Monday, May 27th 2025

QFile Read Binary blockwise

Scheduled Pinned Locked Moved Solved General and Desktop
qfiletcp
2 Posts 1 Posters 1.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.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 16 Jun 2017, 13:17 last edited by
    #1

    Hello everyone,

    I'm trying to send files via a TcpSocket connection.
    Client and server programs are so far finished.
    I can send text-files of any size without problem, that part works fine.

    But I get unreadable files if it is any other file-format like png/bmp or a sqlitedb is transfered.
    So, I'm guessing, I don't read the file correctly?

    Reading and writing basicly breaks done to this:

    //Reading the File
    
    qint64 qiSend;
    int iSend = 65525; //2 byte int = 0 - 65 535 //10 Byte For tcp-header
    char readData[65525];
    ...
    qiSend = file.read(readData,iSend);
    
    //Writing to file
    QByteArray baWrite;
    
    ...
    
    if(writeFile.isOpen()){
                bytesWritten =writeFile.write(baWrite);
                if(bytesWritten != baWrite.size())
                    qDebug() << "could not write all bytes" << bytesWritten << "of" << baWrite.size();
    }
    

    Anyone an idea, what I'm doing wrong?


    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.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 16 Jun 2017, 13:27 last edited by
      #2

      Never mind,
      @tobias-hunger in this thread 6 years ago is right.

      I changed:

      qiSend = file.read(readData,iSend);
      

      to

      QByteArray b = file.read(iSend);
      

      And now I'm getting all needed bytes.


      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.

      1 Reply Last reply
      2

      2/2

      16 Jun 2017, 13:27

      • Login

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