Hi again.
I have this problem. I have two network applications. First application write into socket QByteArray
streamOut << quint32(Data::PluginData) << pluginName << quint32(ProgramViewerMenu::NewImage) << shot.toImage();
first number is 2 and second is 1.
socket->write(array);
QByteArray array = new QByteArray();
QDataStream stream(array, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_4_4);
streamOut << quint32(Data::PluginData) << pluginName << quint32(ProgramViewerMenu::NewImage) << shot.toImage();
first number is 2 and second is 1.
socket->write(array);
To copy to clipboard, switch view to plain text mode
In other application I read the first number
quint32 dataType;
streamOut >> dataType;
qDebug() << "data thread dataType" << dataType;
array = socket->readAll();
QDataStream streamOut(socket);
streamOut.setVersion(QDataStream::Qt_4_4);
quint32 dataType;
streamOut >> dataType;
qDebug() << "data thread dataType" << dataType;
QByteArray array;
array = socket->readAll();
To copy to clipboard, switch view to plain text mode
and than te array with remaining data give to other class of this application by signal and slot. Than I read the pluginName which is QString and it read it correctly. Than I pass the array to another class like a argument in function
streamOut >> name;
menu->readData(array);
QDataStream streamOut(array);
streamOut.setVersion(QDataStream::Qt_4_4);
QString name;
streamOut >> name;
menu->readData(array);
To copy to clipboard, switch view to plain text mode
In that class I want to read the second number
quint32 data;
stream >> data;
QDataStream stream(array);
stream.setVersion(QDataStream::Qt_4_4);
quint32 data;
stream >> data;
To copy to clipboard, switch view to plain text mode
But this number is not 1 like I wrote but 28 and I dont know why. When I read all data in one class without passing it, it reads it corretly.
So is there any other way how to write to and read from QByteArray? Or do I have to do something to prepare data for passing to another class?
Thank you.
Bookmarks