开发者

compile error using qFromBigEndian

开发者 https://www.devze.com 2023-01-08 19:10 出处:网络
I\'m trying to use qFromBigEndian to read a 32-bit int from a byte stream received over a udp socket.

I'm trying to use qFromBigEndian to read a 32-bit int from a byte stream received over a udp socket.

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

Compiling this gives 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 rep开发者_Go百科resentation. Note: Template type T can either be a qint16, qint32 or qint64.

Obviously I'm doing something a bit silly and I am already hanging my head in shame. Can someone please explain my obvious mistake?


Note that qFromBigEndian(const uchar *src) is a function template.

You're missing the template parameter, use

addr = qFromBigEndian<qint32>(data);

instead, and things will work as expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号