QT 和webservice的demo,查询手机号码归属地信息

C++访问WebService (需要密码验证)

文章链接:https://blog.csdn.net/z_y__l/article/details/105811563.

查询手机号码归属地信息的qt demo

在这个链接中有很多好玩的webservice的接口 http://www.webxml.com.cn/zh_cn/web_services.aspx
找到查询手机号码归属地信息的地址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

通过gsoap生产C++文件
在这里插入图片描述
创建QT DEMO
在这里插入图片描述

https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw
以下为具体的代码和Pro文件
提示gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法 是添加预定义 WITH_NONAMESPACES

//CPP 文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "gsoap28/soapMobileCodeWSSoapProxy.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("查询手机号码归属地webservice demo");
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(slotSearch()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slotSearch()
{
    MobileCodeWSSoapProxy mcsp;
    _ns1__getMobileCodeInfo para;
    _ns1__getMobileCodeInfoResponse resp;

    auto archiveWString = ui->lineEdit->text().toStdWString();
    auto mobileCode = const_cast<wchar_t *>(archiveWString.c_str());//wstring 转为 wchar_t *
    para.mobileCode = mobileCode;

    if(mcsp.getMobileCodeInfo(&para,resp) != SOAP_OK)
    {
        ui->textEdit->append(QString("search %1 is failed").arg(ui->lineEdit->text()));
        return;
    }

    QString recv;
    recv = QString::fromStdWString(resp.getMobileCodeInfoResult);
    ui->textEdit->append(recv);
}

pro文件

#-------------------------------------------------
#
# Project created by QtCreator 2020-05-27T22:25:55
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = soapphone
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.

#提示gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法 是添加预定义 WITH_NONAMESPACES

DEFINES += QT_DEPRECATED_WARNINGS WITH_NONAMESPACES

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp \
    gsoap28/soapC.cpp \
    gsoap28/soapMobileCodeWSSoapProxy.cpp \
    gsoap28/stdsoap2.cpp

HEADERS += \
        mainwindow.h \
    gsoap28/MobileCodeWSSoap.nsmap \
    gsoap28/soapH.h \
    gsoap28/soapMobileCodeWSSoapProxy.h \
    gsoap28/soapStub.h \
    gsoap28/WebService.h \
    gsoap28/stdsoap2.h

FORMS += \
        mainwindow.ui
LIBS += -lWs2_32
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

DEMO 下载链接

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

巧笑笑笑倩兮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值