send custom object with qbytearray
Hello everybody,
I would like to transfer a custom object with qbytearray. I tried to send "TetrixShape board[BoardWidth * BoardHeight];" This is a custom object.
I would think that if you append this to qbytearray that this object will be converted to a bytearray. But this doesn't happen. I get the following error: invalid conversion from 'TetrixShape*' to 'char' and
Can somebody help me?
Thanks
Code:
TetrixShape board[BoardWidth * BoardHeight];
...
data.append(board);
emit send_board(board);
...
{
out << (quint16)0;
out << data;
out.device()->seek(0);
out << (quint16)(data.size() - sizeof(quint16));
connection->write(data);
qDebug()<<data;
}
Re: send custom object with qbytearray
Re: send custom object with qbytearray
Sorry, I was a little impatient. :rolleyes:
Re: send custom object with qbytearray
There is no magic in programming: you cannot convert complex data structures into simple byte streams without some effort.
You also cannot do it without understanding some basic C++.
You can use QDataStream to create a byte array that can be read at the other end (assuming it is a Qt program) but your send_data(), or should that be send_board(), routine is horribly confused. It creates a local copy of the byte array passed in {14}, then opens a stream on that copy {16}, tries to write itself on that stream {18}, updates some byte counts and then sends it. I am not sure what the result will be (4 bytes?) but I expect it is not pretty and certainly not what you expect.