1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/****************************************************************************
**
** This file is part of the KD Soap project.
**
** SPDX-FileCopyrightText: 2011 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
**
** SPDX-License-Identifier: MIT
**
****************************************************************************/
#include "helloworld_client.h"
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QTextBrowser>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
m_service.setEndPoint(QLatin1String("http://localhost:8081"));
m_service.setSoapVersion(KDSoapClientInterface::SOAP1_2);
connect(&m_service, &Hello_Service::sayHelloDone, this, &MainWindow::sayHelloDone);
connect(&m_service, &Hello_Service::sayHelloError, this, &MainWindow::sayHelloError);
QVBoxLayout *layout = new QVBoxLayout(this);
m_browser = new QTextBrowser;
QLabel *label = new QLabel;
label->setWordWrap(true);
label->setText(tr("<qt><p>This is a simple client/server demo. Start bin/helloworld_server separately on the commandline.</p>"
"<p>Clicking "Send" will make a sayHello() soap call. To trigger an error, leave the input field empty and click "
""Send".</p>"));
layout->addWidget(label);
layout->addWidget(m_browser);
QWidget *w1 = new QWidget;
QHBoxLayout *l1 = new QHBoxLayout(w1);
l1->setContentsMargins(0, 0, 0, 0);
m_input = new QLineEdit;
l1->addWidget(m_input);
QPushButton *pb1 = new QPushButton(tr("Send"));
l1->addWidget(pb1);
connect(m_input, &QLineEdit::returnPressed, this, &MainWindow::sayHello);
connect(pb1, &QAbstractButton::clicked, this, &MainWindow::sayHello);
layout->addWidget(w1);
m_input->setFocus();
}
void MainWindow::sayHello()
{
m_service.asyncSayHello(m_input->text().trimmed());
m_input->clear();
}
void MainWindow::sayHelloDone(const QString &reply)
{
m_browser->append(tr("Reply from server: <font color=\"darkgreen\">%1</font>").arg(reply));
}
void MainWindow::sayHelloError(const KDSoapMessage &fault)
{
m_browser->append(tr("Error from server: <font color=\"red\">%1</font>").arg(fault.faultAsString()));
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
|