Compile the error with qFromBigEndian

I am trying to use qFromBigEndian to read a 32 bit int from a byte stream received via an udp socket.

void processData(uchar *data)
{
  qint32 addr;
  addr = qFromBigEndian(data);
}

When compiling, this leads to the following error: error: invalid conversion from 'uchar *' to 'qint32'

The Qt documentation says:

T qFromBigEndian (const uchar * src)

Reads a big-endian number from memory location src and returns the number in the host byte order representation. Note: Template type T can either be a qint16, qint32 or qint64.

Obviously I'm doing something a little stupid, and I'm already embarrassing my head. Can someone explain my obvious mistake?

+3
source share
1 answer

Please note that this qFromBigEndian(const uchar *src)is a function template.

You are missing a template parameter, use

addr = qFromBigEndian<qint32>(data);

and everything will work as expected.

+6
source

Source: https://habr.com/ru/post/1756163/


All Articles