PDA

View Full Version : Write each receiving QByteArray to end of a file



Alex22
11th November 2016, 12:16
Hi, I have a serial connection that I put each coming data into a QByteArray:




connect(&SerialPort, SIGNAL(readyRead()), this, SLOT(slot_reading()));





//the slot:
void Cserial::slot_reading()
{
QByteArray DataReading = SerialPort.readAll();
}


I need to save all coming data into a file. So i must gather each QByteArray::DataReading and at the end, saving all of them into a file (by pushing a QPushButtom in name of "save").
1-How could I gather all data?
and then
2-how can I save into a file?

Thanks a lot for any help

anda_skoa
11th November 2016, 18:17
Is the button triggered file creation a "must have"?
Otherwise you could just write the incoming data directly into a file, appending each time.

Cheers,
_

Alex22
11th November 2016, 19:30
Is the button triggered file creation a "must have"?


Thanks for replying. Yes a pushButton must be.



write the incoming data directly into a file, appending each time.


Working with a file makes process speed of the project too low.

anda_skoa
12th November 2016, 09:51
Ok, then create a QBuffer and write the incoming data into that.

Get the buffer's content on button click.

Cheers,
_