Zingam
18th June 2014, 09:30
I need to send/receive 4 bytes over TCP to some device (that I don't have yet). I intend to use QTcpSocket.
My understanding is that I need to copy/extract these 4 bytes to/from QByteArray and because the device is not using a Qt device I would not be able to use QDataStream. So how should I put 4 bytes into QByteArray, what would be the legit way? I read some posts here on the forum too but I am pretty confused and unsure how to do it.
These are the bytes. Currently they are from my test/study app:
QString stringByte01 = ui->lineEdit_Byte01->text();
QString stringByte02 = ui->lineEdit_Byte02->text();
QString stringByte03 = ui->lineEdit_Byte03->text();
QString stringByte04 = ui->lineEdit_Byte04->text();
char byte01 = stringByte01.at(0).toLatin1();
quint8 byte02 = (quint8) stringByte02.toUShort();
qint8 byte03 = (qint8) stringByte03.toShort();
quint8 byte04 = (quint8) stringByte04.toShort();
My understanding is that I need to copy/extract these 4 bytes to/from QByteArray and because the device is not using a Qt device I would not be able to use QDataStream. So how should I put 4 bytes into QByteArray, what would be the legit way? I read some posts here on the forum too but I am pretty confused and unsure how to do it.
These are the bytes. Currently they are from my test/study app:
QString stringByte01 = ui->lineEdit_Byte01->text();
QString stringByte02 = ui->lineEdit_Byte02->text();
QString stringByte03 = ui->lineEdit_Byte03->text();
QString stringByte04 = ui->lineEdit_Byte04->text();
char byte01 = stringByte01.at(0).toLatin1();
quint8 byte02 = (quint8) stringByte02.toUShort();
qint8 byte03 = (qint8) stringByte03.toShort();
quint8 byte04 = (quint8) stringByte04.toShort();