PDA

View Full Version : Cannot understand program



Blitzor DDD
15th August 2016, 16:20
Hello!

I am trying to dissect a program and got stuck with one function:


void SerialPortHandler::sendTrackPause()
{
// qDebug() << "sendTrackPause";
QByteArray byteArr;
QDataStream out(&byteArr, QIODevice::WriteOnly);
out << ActionType::Track << TrackType::Pause << '\n';
serial->write(byteArr);
}

serial is an object of QSerialPort.
This function clearly pauses a player.

But what's going on under the hood?
For what sake do we need QByteArray and QDataStream?

anda_skoa
15th August 2016, 18:59
The QByteArray is not needed as the QSerialPort is also a QIODevice and the QDataStream could directly write into it.

Depending on the types of ActionType::Track and TrackType::Pause it the QDataStream might just be used as a convenience wrapper to get multipe byte integered serialized in a specified byte order.

Cheers,
_