zoukankan      html  css  js  c++  java
  • 〖Linux〗Qt+gsoap开发客户端程序,服务端地址设定的字符串转换处理

    之所以写出来,是由于经常因为这个问题屡屡丢面子..

    一般情况下,QString转换成(char*),我们一般直接使用:

      char *str = qstr->text().toLatin1().data();

    当然这也本身就一点问题也没有,假如得到的str为"123",那么str就点4个字符的空间,最后一个字符是''

    可就是这么一个'',在设定gsoap的server的时候,它并不需要,被坑了好几回了,..

      出错的信息大概都是这样子的:

    Starting /media/Study/Workspace/Qt/build-zigbeeClient-Desktop-Release/zigbeeClient...
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://localhost:8888"><SOAP-ENV:Body><ns:temp SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><subdev>49</subdev></ns:temp></SOAP-ENV:Body></SOAP-ENV:Envelope>
    接着,程序就死在这里..

      或者是这样子的出错信息:

    SOAP 1.2 fault: SOAP-ENV:Sender[no subcode]
    "Host not found"
    Detail: get host by name failed in tcp_connect()

    解决方法其实很容易的,就把最后一个字符''去掉了就好了,我是这么写的:

        char *custserver = ui->serverlineEdit->text().toLatin1().data();
        char *custservertmp = (char *)malloc(strlen(custserver));       //to avoid the end of ''
        strncpy(custservertmp,custserver,strlen(custserver));           //to avoid the end of ''

    解析,假如custserver为"127.0.0.1:4567",使用strlen(custserver)得到的长度是14,而实际custserver占用的空间为15

    那么,再定义一个char *custservertmp,分配空间为14,使用strncpy,把custserver前边的14个字符复制给custservertmp;

    然后,设定好服务端的地址,gsoap+Qt客户端运行很OK。

  • 相关阅读:
    用Taro写一个微信小程序——版本升级
    matlab subplot 的边距(with tight margins)
    Nginx(Tengine) 解决 unknown directive "stream" 问题
    MinIO 分布式集群搭建
    Docker 及 Docker Compose 日常操作(团队培训材料)
    基于 AdoptOpenjdk 官方 Dockerfile 制作 jre8 镜像(修改字符集和时区)
    Syncthing 开源文件同步工具
    Harbor 2.2.0 搭建与使用
    Centos7 使用 chronyd 进行时钟同步
    Centos7 安装 Python3 及配置国内源、虚拟环境
  • 原文地址:https://www.cnblogs.com/scue/p/3485049.html
Copyright © 2011-2022 走看看