diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
commit | ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b (patch) | |
tree | 3379cee43d6acae95312e51e6cd05c3c4198a95e /examples/webchannel/standalone/main.cpp | |
parent | 749951c19cbb7d301bed20f24d16dd4e713485c2 (diff) | |
parent | d84318e98aa3cbac11b4f95b3581e95aab96a34a (diff) | |
download | qtwebchannel-ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b.tar.gz |
Merge remote-tracking branch 'origin/5.9' into 5.10v5.10.0-beta3v5.10.0-beta2v5.10.0-beta1
Change-Id: I54f0bcd46ffb496156e46d723275cdd29601e45c
Diffstat (limited to 'examples/webchannel/standalone/main.cpp')
-rw-r--r-- | examples/webchannel/standalone/main.cpp | 90 |
1 files changed, 15 insertions, 75 deletions
diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index b53e9a6..3ea66ad 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -48,81 +48,19 @@ ** ****************************************************************************/ -#include "qwebchannel.h" +#include "dialog.h" +#include "core.h" +#include "../shared/websocketclientwrapper.h" +#include "../shared/websockettransport.h" #include <QApplication> -#include <QDialog> -#include <QVariantMap> #include <QDesktopServices> -#include <QUrl> +#include <QDialog> #include <QDir> #include <QFileInfo> -#include <QtWebSockets/QWebSocketServer> - -#include "../shared/websocketclientwrapper.h" -#include "../shared/websockettransport.h" - -#include "ui_dialog.h" - -/*! - An instance of this class gets published over the WebChannel and is then accessible to HTML clients. -*/ -class Dialog : public QObject -{ - Q_OBJECT - -public: - explicit Dialog(QObject *parent = 0) - : QObject(parent) - { - ui.setupUi(&dialog); - dialog.show(); - - connect(ui.send, SIGNAL(clicked()), SLOT(clicked())); - } - - void displayMessage(const QString &message) - { - ui.output->appendPlainText(message); - } - -signals: - /*! - This signal is emitted from the C++ side and the text displayed on the HTML client side. - */ - void sendText(const QString &text); - -public slots: - /*! - This slot is invoked from the HTML client side and the text displayed on the server side. - */ - void receiveText(const QString &text) - { - displayMessage(tr("Received message: %1").arg(text)); - } - -private slots: - /*! - Note that this slot is private and thus not accessible to HTML clients. - */ - void clicked() - { - const QString text = ui.input->text(); - - if (text.isEmpty()) { - return; - } - - emit sendText(text); - displayMessage(tr("Sent message: %1").arg(text)); - - ui.input->clear(); - } - -private: - QDialog dialog; - Ui::Dialog ui; -}; +#include <QUrl> +#include <QWebChannel> +#include <QWebSocketServer> int main(int argc, char** argv) { @@ -148,17 +86,19 @@ int main(int argc, char** argv) QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected, &channel, &QWebChannel::connectTo); - // setup the dialog and publish it to the QWebChannel + // setup the UI Dialog dialog; - channel.registerObject(QStringLiteral("dialog"), &dialog); + + // setup the core and publish it to the QWebChannel + Core core(&dialog); + channel.registerObject(QStringLiteral("core"), &core); // open a browser window with the client HTML page QUrl url = QUrl::fromLocalFile(BUILD_DIR "/index.html"); QDesktopServices::openUrl(url); - dialog.displayMessage(QObject::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString())); + dialog.displayMessage(Dialog::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString())); + dialog.show(); return app.exec(); } - -#include "main.moc" |