0

I would like to send a struct :

typedef struct myStruct
    {
       int nb_trame;
       bool tabBool[20];
    } myStruct;

via a QUpdSocket.

I would like to not serialize it (so please no answer with QDataStream... ^^).

Will this work ? :

myStruct a;
//set a variable
mySocket->writeDatagram( (const char*) &a, sizeof(a), someQHostAddress, somePort);
0xPunt
  • 313
  • 1
  • 4
  • 21

1 Answers1

1

Due to padding, you can't simply take the address and the size of the struct.
You will need to also supply a pragma for packing.
This would be a compiler extension.

For example, in GCC:

typedef struct __attribute__((packed))
{
    int nb_trame;
    bool tabBool[20];
} myStruct;
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271