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. Large incoming data to QByteArray and what to do with it?
Forum Update on Monday, May 27th 2025

Large incoming data to QByteArray and what to do with it?

Scheduled Pinned Locked Moved Solved General and Desktop
qtemporaryfileqbytearrayqiodevice
4 Posts 3 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.
  • S Offline
    S Offline
    scottnat
    wrote on last edited by
    #1

    Hello everyone.

    I have an audio recording application that reads audio data from a microphone system. The user presses record and after an unknown duration he is done recording, he will click to save the file.

    Each second streams about 8MB of data into a qbuffer - qbytearray.
    On average, the user suggests about 15 mins worth of recording. However, it could be shorter/longer.
    For 15 mins, size = 15m * 60s * 8 M = 7.03GB. (I only managed to do 3 minutes before my pc crashed)

    1. Any suggestions on what I can do to prevent having so much data lingering in my qbytearray?

    2. Would writing directly to an open file be better?

    3. Can I keep a file stream open while I collect data before writing it over?

    4. What about temporary files? I have tried creating temporary files with the QTemporaryFile class and it gets saved to my .../temp/ folder. I don't know how how I can translate that temp file into a permanent file?

    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • S scottnat

      Hello everyone.

      I have an audio recording application that reads audio data from a microphone system. The user presses record and after an unknown duration he is done recording, he will click to save the file.

      Each second streams about 8MB of data into a qbuffer - qbytearray.
      On average, the user suggests about 15 mins worth of recording. However, it could be shorter/longer.
      For 15 mins, size = 15m * 60s * 8 M = 7.03GB. (I only managed to do 3 minutes before my pc crashed)

      1. Any suggestions on what I can do to prevent having so much data lingering in my qbytearray?

      2. Would writing directly to an open file be better?

      3. Can I keep a file stream open while I collect data before writing it over?

      4. What about temporary files? I have tried creating temporary files with the QTemporaryFile class and it gets saved to my .../temp/ folder. I don't know how how I can translate that temp file into a permanent file?

      Thanks.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @scottnat

      1. Well, write it to a file
      2. Yes
      3. Sure
      4. Simply move the file to final location. See http://doc.qt.io/qt-5/qdir.html#rename

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

      1 Reply Last reply
      4
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        QBuffer is a QIODevice. QFile is one, too. So, you can combine using QByteArray as buffer and keep saving to QFile at the same time, if you want to. I think it would be easier to just write directly to a QFile, though.

        My main suggestion is to use QDataStream to stream the data into the file. This way you won't be consuming much RAM - just enough to receive and save the audio as it arrives. This should solve both 1 & 2.

          • yes.
          • use QSaveFile instead of QTemporaryFile, if you want to. But using normal file and data stream is the way to go, I think.

        Some pseudo code to get you started:

        // init
        QDataStream stream(&file);
        
        // when audio comes in
        void readAudio(const QByteArray &audioPacket) {
          stream << audioPacket;
        }
        

        (Z(:^

        S 1 Reply Last reply
        5
        • sierdzioS sierdzio

          QBuffer is a QIODevice. QFile is one, too. So, you can combine using QByteArray as buffer and keep saving to QFile at the same time, if you want to. I think it would be easier to just write directly to a QFile, though.

          My main suggestion is to use QDataStream to stream the data into the file. This way you won't be consuming much RAM - just enough to receive and save the audio as it arrives. This should solve both 1 & 2.

            • yes.
            • use QSaveFile instead of QTemporaryFile, if you want to. But using normal file and data stream is the way to go, I think.

          Some pseudo code to get you started:

          // init
          QDataStream stream(&file);
          
          // when audio comes in
          void readAudio(const QByteArray &audioPacket) {
            stream << audioPacket;
          }
          
          S Offline
          S Offline
          scottnat
          wrote on last edited by
          #4

          @sierdzio and @jsulm

          Thank you both for the suggestions. I will work on number 4 with moving of tempfiles or using a QSaveFile.

          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