QtのQtSoap(Webサービスへのアクセス)

元のアドレス:https//blog.csdn.net/liang19890820/article/details/51673800

関連記事

1. QtのQtSoap(Webサービスへのアクセス) ---- https://www.cnblogs.com/itrena/p/5938317.html

2. QtはWebサービスを呼び出します---- https://www.cnblogs.com/findumars/p/5290140.html

3. WebサービスサービスはQT環境で呼び出され、サーバーはJava環境にあります---- https://blog.csdn.net/weixin_40288738/article/details/88994875?utm_medium=distribute.pc_relevant_download.none- task-blog- baidujs-1.nonecase&depth_1-utm_source = Distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase

4、QTQHttp访问WEBSERVICE范例---- https://blog.csdn.net/cangwu_lee/article/details/1637722?utm_medium = distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.baidujs&depth_1-utm_source = distribute .pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.baidujs

5、QtSoapはWebサービスクライアントを開発します---- https://www.cnblogs.com/findumars/p/5040435.html

6.QtSoapを学ぶ---- https://blog.csdn.net/qq_41622002/article/details/108848775

7. QtSoapがWebサービスを呼び出します(QtSoapは非公式のアプリケーションです) ---- https://www.cnblogs.com/findumars/p/5176087.html

8.QtSoapがWebサービスを呼び出す---- https://www.xuebuyuan.com/2174829.html

9. QtのQtSoap(Webサービスへのアクセス)---- http://t.zoukankan.com/itrena-p-5938317.html

10、QtSoapMOSFET递多種クラス型参数---- https://blog.csdn.net/zbc415766331/article/details/48313009?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control&dist_request_id=1b945b0b- 14dd-41f5-bdb0-fddc631be061&depth_1-utm_source = Distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control

 

簡単な説明

Qt自体は、WebServiceを呼び出すためのソリューションであるQtSoapを提供します。ソースコードと例を参照してください:qt-solutions-qtsoap

著作権表示:Yiqu、Ersanliは、ブロガーの許可なしに転載することはできません。

ダウンロードしてコンパイルする

ソースコードをダウンロードした後、いくつかの場所を変更する必要があります(私のバージョンはQt5です)。エラープロンプトに従って変更するだけです。非常に簡単です。

コンパイル後、QtSolutions_SOAP-headd.libとQtSolutions_SOAP-headd.dllが生成されます。

使用する

QtSolutions_SOAP-headd.libをlibディレクトリにコピーし、qtsoap.hをインクルードディレクトリにコピーします。

プロでライブラリファイルとライブラリディレクトリを追加します。

<span style="color:#000000"><code class="language-Qt">INCLUDEPATH <span style="color:#4f4f4f !important">+=</span> $<span style="color:#4f4f4f !important">$PWD</span>/include
LIBS <span style="color:#4f4f4f !important">+=</span> <span style="color:#98c379">-L</span>$<span style="color:#4f4f4f !important">$PWD</span>/lib <span style="color:#98c379">-lQtSolutions_SOAP</span><span style="color:#98c379">-headd</span></code></span>

分析例

以下では、例として「Get Tencent QQ online status」を取り上げます。WebXml.com.cnを参照してください。これには、携帯電話番号の帰属クエリ、電子メールアドレスの確認、都市の天気予報クエリなど、多数のWebサービスが含まれています。等

SOAP 1.1

以下は、SOAP1.1の要求と応答の例です。表示されるプレースホルダーは、実際の値に置き換える必要があります。

ここに写真の説明を書いてください

効果

ここに写真の説明を書いてください

ソースコード

<span style="color:#000000"><code class="language-Qt"><span style="color:#880000 !important"><em>// 构建控件</em></span>
m_pQQLabel <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QLabel(this);
m_pStateLabel <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QLabel(this);
m_pQQLineEdit <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QLineEdit(this);
m_pStateLineEdit <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QLineEdit(this);
m_pSubmitButton <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QPushButton(this);

m_pStateLineEdit<span style="color:#4f4f4f !important">-></span>setReadOnly(<span style="color:#006666 !important">true</span>);
m_pQQLabel<span style="color:#4f4f4f !important">-></span>setText(QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"QQ号码:"</span>));
m_pStateLabel<span style="color:#4f4f4f !important">-></span>setText(QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"QQ状态:"</span>));
m_pSubmitButton<span style="color:#4f4f4f !important">-></span>setText(QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"提交"</span>));

QGridLayout <span style="color:#4f4f4f !important">*</span>pLayout <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QGridLayout();
pLayout<span style="color:#4f4f4f !important">-></span>addWidget(m_pQQLabel, <span style="color:#006666 !important">0</span>, <span style="color:#006666 !important">0</span>);
pLayout<span style="color:#4f4f4f !important">-></span>addWidget(m_pQQLineEdit, <span style="color:#006666 !important">0</span>, <span style="color:#006666 !important">1</span>);
pLayout<span style="color:#4f4f4f !important">-></span>addWidget(m_pStateLabel, <span style="color:#006666 !important">1</span>, <span style="color:#006666 !important">0</span>);
pLayout<span style="color:#4f4f4f !important">-></span>addWidget(m_pStateLineEdit, <span style="color:#006666 !important">1</span>, <span style="color:#006666 !important">1</span>);
pLayout<span style="color:#4f4f4f !important">-></span>addWidget(m_pSubmitButton, <span style="color:#006666 !important">2</span>, <span style="color:#006666 !important">1</span>, <span style="color:#006666 !important">1</span>, <span style="color:#006666 !important">1</span>, Qt<span style="color:#006666 !important">::AlignRight</span>);
pLayout<span style="color:#4f4f4f !important">-></span>setSpacing(<span style="color:#006666 !important">10</span>);
pLayout<span style="color:#4f4f4f !important">-></span>setContentsMargins(<span style="color:#006666 !important">10</span>, <span style="color:#006666 !important">10</span>, <span style="color:#006666 !important">10</span>, <span style="color:#006666 !important">10</span>);
setLayout(pLayout);

<span style="color:#880000 !important"><em>// 连接信号槽</em></span>
m_pHttp <span style="color:#4f4f4f !important">=</span> <span style="color:#006666 !important">new</span> QtSoapHttpTransport(this);
connect(m_pSubmitButton, SIGNAL(clicked()), this, SLOT(onSubmit()));
connect(m_pHttp, SIGNAL(responseReady(const QtSoapMessage <span style="color:#4f4f4f !important">&</span>)), this, SLOT(onResponse(const QtSoapMessage <span style="color:#4f4f4f !important">&</span>)));

<span style="color:#880000 !important"><em>// 提交请求</em></span>
<span style="color:#006666 !important">void</span> MainWindow<span style="color:#006666 !important">::onSubmit</span>()
{
    QtSoapMessage message;

    <span style="color:#880000 !important"><em>// 设置方法</em></span>
    message<span style="color:#4f4f4f !important">.</span>setMethod(<span style="color:#009900 !important">"qqCheckOnline"</span>, <span style="color:#009900 !important">"http://WebXml.com.cn/"</span>);

    <span style="color:#880000 !important"><em>// 设置动作</em></span>
    m_pHttp<span style="color:#4f4f4f !important">-></span>setAction(<span style="color:#009900 !important">"http://WebXml.com.cn/qqCheckOnline"</span>);

    <span style="color:#880000 !important"><em>// 设置主机</em></span>
    m_pHttp<span style="color:#4f4f4f !important">-></span>setHost(<span style="color:#009900 !important">"www.webxml.com.cn"</span>);

    <span style="color:#880000 !important"><em>// 添加方法参数</em></span>
    QString strQQ <span style="color:#4f4f4f !important">=</span> m_pQQLineEdit<span style="color:#4f4f4f !important">-></span>text();
    message<span style="color:#4f4f4f !important">.</span>addMethodArgument(<span style="color:#009900 !important">"qqCode"</span>, <span style="color:#009900 !important">""</span>, strQQ);
    QString strXML <span style="color:#4f4f4f !important">=</span> message<span style="color:#4f4f4f !important">.</span>toXmlString();

    <span style="color:#880000 !important"><em>// 提交请求</em></span>
    m_pHttp<span style="color:#4f4f4f !important">-></span>submitRequest(message, <span style="color:#009900 !important">"/webservices/qqOnlineWebService.asmx"</span>);
}

<span style="color:#006666 !important">void</span> MainWindow<span style="color:#006666 !important">::onResponse</span>(const QtSoapMessage <span style="color:#4f4f4f !important">&</span>response)
{
    QString strXML <span style="color:#4f4f4f !important">=</span> response<span style="color:#4f4f4f !important">.</span>toXmlString();
    QDomDocument doc;
    doc<span style="color:#4f4f4f !important">.</span>setContent(strXML);

    <span style="color:#880000 !important"><em>// 接在在线状态</em></span>
    QDomNodeList nodeList <span style="color:#4f4f4f !important">=</span> doc<span style="color:#4f4f4f !important">.</span>elementsByTagName(<span style="color:#009900 !important">"qqCheckOnlineResult"</span>);
    <span style="color:#000088 !important">if</span> (<span style="color:#4f4f4f !important">!</span>nodeList<span style="color:#4f4f4f !important">.</span>isEmpty())
    {
        QDomNode node <span style="color:#4f4f4f !important">=</span> nodeList<span style="color:#4f4f4f !important">.</span>at(<span style="color:#006666 !important">0</span>);
        QString strResult <span style="color:#4f4f4f !important">=</span> node<span style="color:#4f4f4f !important">.</span>toElement()<span style="color:#4f4f4f !important">.</span>text();
        QString strState(<span style="color:#009900 !important">"N/A"</span>);
        <span style="color:#000088 !important">if</span> (QString<span style="color:#006666 !important">::compare</span>(strResult, <span style="color:#009900 !important">"Y"</span>) <span style="color:#4f4f4f !important">==</span><span style="color:#006666 !important">0</span>)
        {
            strState <span style="color:#4f4f4f !important">=</span> QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"在线"</span>);
        }
        <span style="color:#000088 !important">else</span> <span style="color:#000088 !important">if</span> (QString<span style="color:#006666 !important">::compare</span>(strResult, <span style="color:#009900 !important">"N"</span>) <span style="color:#4f4f4f !important">==</span> <span style="color:#006666 !important">0</span>)
        {
            strState <span style="color:#4f4f4f !important">=</span> QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"离线"</span>);
        }
        <span style="color:#000088 !important">else</span> <span style="color:#000088 !important">if</span> (QString<span style="color:#006666 !important">::compare</span>(strResult, <span style="color:#009900 !important">"E"</span>) <span style="color:#4f4f4f !important">==</span> <span style="color:#006666 !important">0</span>)
        {
            strState <span style="color:#4f4f4f !important">=</span> QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"QQ号码错误"</span>);
        }
        <span style="color:#000088 !important">else</span> <span style="color:#000088 !important">if</span> (QString<span style="color:#006666 !important">::compare</span>(strResult, <span style="color:#009900 !important">"A"</span>) <span style="color:#4f4f4f !important">==</span> <span style="color:#006666 !important">0</span>)
        {
            strState <span style="color:#4f4f4f !important">=</span> QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"商业用户验证失败"</span>);
        }
        <span style="color:#000088 !important">else</span> <span style="color:#000088 !important">if</span> (QString<span style="color:#006666 !important">::compare</span>(strResult, <span style="color:#009900 !important">"V"</span>) <span style="color:#4f4f4f !important">==</span> <span style="color:#006666 !important">0</span>)
        {
            strState <span style="color:#4f4f4f !important">=</span> QString<span style="color:#006666 !important">::fromLocal8Bit</span>(<span style="color:#009900 !important">"免费用户超过数量"</span>);
        }
        m_pStateLineEdit<span style="color:#4f4f4f !important">-></span>setText(strState);
    }
}</code></span>
 

オンライン検証にqq番号を使用することもできます:qqCheckOnline

その他の参考資料

おすすめ

転載: blog.csdn.net/xqhrs232/article/details/113786983