简体   繁体   English

在 QT 中将 gpointer 转换为 QByteArray

[英]Convert gpointer to QByteArray in QT

How can I convert gpointer bytes (FT_BYTES) to QByteArray in Qt?如何在 Qt 中将gpointer字节 (FT_BYTES) 转换为QByteArray Point:观点:

a) gpointer is a type like void* in glib Linux package. a) gpointer是 glib Linux package 中的void*类型。

b) A hex dump like a0 23 5c which is stored as gpointer and I like to convert it to hex in QByteArray format b) 像a0 23 5c这样的十六进制转储,它存储为gpointer ,我喜欢将其转换为QByteArray格式的十六进制

QByteArray createQBAfromGP(gpointer gp, int byteCount)
{
    return QByteArray::fromRawData((char *)gp, byteCount);
}

Be aware that the bytes are not copied.请注意,字节不会被复制。 The QByteArray is merely a view into the original memory. QByteArray只是原始 memory 的一个视图。 If you want them copied, you can如果你想复制它们,你可以

QByteArray convertToQBA(gpointer gp, int byteCount)
{
    return QByteArray().append(QByteArray::fromRawData((char *)gp, byteCount));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM