Confirmation:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QByteArray>
#include <QDataStream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char *argv[])
{
qint32 random1;
qint32 random2;
qint32 oper;
//generate random numbers
srand(time(NULL));
random1=rand()%256;
//sleep(3);
srand(time(NULL));
random2=rand()%256;
srand((time(NULL)+5));
oper=rand()%5;
qDebug() << "Test hex";
qDebug() << "";
stream << (quint16)65502;
array.clear();
stream << (quint16)65502 << (quint8)random1 << (quint8)random2 << (quint8)oper;
qDebug() << "Hex =" << array.toHex();
array.clear();
stream1 << (quint16)65502;
array.clear();
stream2 << (quint16)65502 << (quint8)random1 << (quint8)random2 << (quint8)oper;
qDebug() << "Hex =" << array.toHex();
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QByteArray>
#include <QDataStream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qint32 random1;
qint32 random2;
qint32 oper;
//generate random numbers
srand(time(NULL));
random1=rand()%256;
//sleep(3);
srand(time(NULL));
random2=rand()%256;
srand((time(NULL)+5));
oper=rand()%5;
qDebug() << "Test hex";
qDebug() << "";
QByteArray array;
QDataStream stream(&array,QIODevice::ReadWrite);
stream << (quint16)65502;
array.clear();
stream << (quint16)65502 << (quint8)random1 << (quint8)random2 << (quint8)oper;
qDebug() << "Hex =" << array.toHex();
QDataStream stream1(&array, QIODevice::ReadWrite);
QDataStream stream2(&array, QIODevice::ReadWrite);
array.clear();
stream1 << (quint16)65502;
array.clear();
stream2 << (quint16)65502 << (quint8)random1 << (quint8)random2 << (quint8)oper;
qDebug() << "Hex =" << array.toHex();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Results:
Test hex
Hex = "ffdeffde5d5d01"
Hex = "ffde5d5d01"
Test hex
Hex = "ffdeffde5d5d01"
Hex = "ffde5d5d01"
To copy to clipboard, switch view to plain text mode
Edit: All I can say is that QDataStream is not meant to be used like this.
Bookmarks