问题标签 [qbytearray]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1413 浏览

qt - quint16 on qbytearray

i need add on firt position of qbytearray a quint16 and after read it: How can i to do it?

I have try this:

Thanks you very much

I got add with:

but i don't know as read it

Thanks

0 投票
1 回答
889 浏览

c++ - QDataStream 和 quint16 序列化怪异

我编写了一个小型 Packet 类,由一些 quint8、quint16、QByteArrays 和一个 quint32 组成,它有一个 toByteArray() 方法来返回对象的序列化版本,符合协议规范。

数据包规格

  • 协议标识符 [4 字节](版本 1 = 0x74697331)
  • 会话 ID,一个用时间戳 + 用户 IP 加盐的 MD5 哈希。[16 字节]
  • 命令 ID [1 字节]
  • 参数大小 [2 字节]
  • Args [1-8,192 字节]
  • CRC-B (X-25) [2 字节]

大多数数据可以很好地序列化。例外是最后一个 quint16(我的 crc),它似乎被破坏了。

我不认为问题出在我班级的声明中。我在这个代码示例中重新创建了序列化函数,它演示了我收到的错误,没有我的数据包类。(但最终的 QByteArray 布局相同)

(更多) 最小可重现测试用例

这是我得到的输出:

73 69 74 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 e 0 74 65 73 74 0 31 32 33 34 71 77 65 72 0 ffffffffffffffa2 ffffffffffffffb5

最后两个应该是 0xa2、0xb5。我想这是某种对齐问题。有什么方法可以纠正这个问题,同时仍然符合数据包规范?

0 投票
3 回答
1334 浏览

c# - 在 C++ 中为 Azure 中的 blobId 将 int 转换为 little-endian 格式的字节

使用 Azure 的 base64 编码(http://msdn.microsoft.com/en-us/library/dd135726.aspx),我似乎不知道如何取回所需的字符串。我可以在 C# 中执行以下操作。

打印出来(在 LINQPad 中):

在 Qt/C++ 中,我尝试了一些 aporache,它们都返回了错误的值。

如何获得与 C# 版本相同的结果?

0 投票
1 回答
12463 浏览

c++ - qDebug 没有打印包含二进制数据的完整 QByteArray

我有一个QByteArray存储从 GPS 接收到的数据,它是部分二进制和部分 ASCII。我想知道调试建议知道收到了什么,所以我写了qDebug这样的:

我在控制台收到这样的消息:

但突然间我得到了一个新的打印迭代。数据还没有被删除,它已经被附加了。所以新的消息大小例如 3204,明显比以前的打印大。但它的打印结果完全相同(但括号中的新尺寸为 3204)。没有新数据被打印出来,就像之前的消息一样:

我想qDebug停止打印是因为它有一个限制,或者因为它到达了一个终止字符或类似的东西,但我只是在猜测。

对这种行为有任何帮助或解释吗?

0 投票
1 回答
1379 浏览

newline - Qt QTcpSocket QByteArray/QString issues with special characters and proper syntax

I'm having trouble some special characters in Qt, the 2 being the quote and newline. I'm connecting to the server using telnet, and the server automatically puts quotes at the beginning and end of the input for some reason. I'm having trouble removing both the quotes and newline.

The problem with replacing the newline is described below:

My input from telnet: Hello

After the program replaces the newline: " ello (Normal output with quotes would be "Hello")

And replacing the quotes has no effect at all. I have tried also using dual backslashes since it is a RegEx, but both still have the same problems as if there were one. Help is appreciated, thanks.

Edit: This turned out to be qDebug's formatting, not a result of using Telnet or anything.

0 投票
2 回答
8590 浏览

c++ - 在调试过程中如何查看 Qt 对象 QByteArray 的内容?

我的程序使用一些 QByteArray 类型的变量来包含数据(字节)。该字节可能是特殊字符,例如 '\0', 1, ... 所以在调试时我看不到特殊字符后的所有元素。如果我使用 std::vector,我可以看到所有元素。我必须使用 QByteArray 但在调试时我看不到这个变量的所有元素。帮帮我,请!谢谢!

示例:QByteArray bytes(4, '\0'); 现在,如果调试,我只看到“”。但我想看 "'\0', '\0', '\0', '\0'" 或类似的东西。

QDateTime 我也有同样的问题。但我通过这个帮助解决了:http ://www.qtcentre.org/threads/32336-View-QDate-and-QDateTime-in-VisualStudio-debugger

此链接可能会有所帮助,但这不能解决我的问题:http: //qt-project.org/wiki/IDE-debug-helpers

例子:

0 投票
2 回答
757 浏览

qt - QT QBytearray 计数字符

我如何计算 中的字符QByteArray,例如我有QByteArray并且我想知道这个数组中有多少个“*”。

0 投票
3 回答
2459 浏览

qt - Qt 数组 QString

我通过 selectall 查询从 db 获取结果,我想将结果保存在数组中并通过套接字发送。

我收到此错误二进制“=”:未找到采用“const char [16]”类型的右侧操作数的运算符

0 投票
3 回答
15787 浏览

c++ - 仅使用 4 个字节将整数存储到 QByteArray

表示一个整数需要 4 个字节。如何将 an 存储int在 a 中QByteArray以便只占用 4 个字节?

  • QByteArray::number(..)将整数转换为字符串,因此占用超过 4 个字节。
  • QByteArray((const char*)&myInteger,sizeof(int))似乎也不起作用。
0 投票
2 回答
6864 浏览

c++ - 将数字添加到 QByteArray

我有一个QbyteArray 名字"B2"

我想添加一个 2 字节的数字,例如300.

但是当我这样做mybyte.size()3byte!!!!

我的代码是:

我想让它变成2字节。

这是我的输出: