【问题标题】:0x00 hex over TCP socket in QTQT中TCP套接字上的0x00十六进制
【发布时间】:2015-06-03 09:31:31
【问题描述】:

我在通过 tcp 发送 0x00 时遇到问题。 0x01 之类的数据没问题,服务器接收为 00000001,但什么时候是 0x00 - 服务器上没有接收消息。

客户端代码:

QByteArray sender="\x00";
socket.write(sender);

服务器代码:

    QByteArray Data = socket->readAll();
    QString str = QString(Data.toHex());
    qDebug()<<str;

    //disp bytes
    char myByte = Data.at(0);

    for (int i = 7; i >= 0; --i) 
    {
        qDebug() << ((myByte >> i) & 1);
    }

如何发送 0x00 十六进制?

【问题讨论】:

    标签: qt tcp hex bytearray


    【解决方案1】:

    您正在从字符串构造QByteArray,但字符串以字符 0 结尾。所以您的数组为空。

    使用different constructor,即

    const QByteArray sender(1, '\0');
    

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 1970-01-01
      • 2017-03-26
      • 2016-08-01
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多