From f2cc878378ddf9a9b014fd298b4982a47643ba12 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Aug 2017 13:10:34 +0200 Subject: Examples: Use nullptr Change-Id: I93688ed891e1cdd6815af0ea22507190c34c0bba Reviewed-by: Milian Wolff --- examples/webchannel/standalone/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/webchannel/standalone/main.cpp') diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index b53e9a6..0aeb45c 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -72,7 +72,7 @@ class Dialog : public QObject Q_OBJECT public: - explicit Dialog(QObject *parent = 0) + explicit Dialog(QObject *parent = nullptr) : QObject(parent) { ui.setupUi(&dialog); -- cgit v1.2.1 From 046040e4b08972018fcb10ef882a35f7162cb38c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Aug 2017 13:28:23 +0200 Subject: Examples: Use Qt 5 connect Change-Id: I33aa6f8244770bf19b45f69cfc62a5469168418d Reviewed-by: Milian Wolff --- examples/webchannel/standalone/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/webchannel/standalone/main.cpp') diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index 0aeb45c..f468652 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -78,7 +78,7 @@ public: ui.setupUi(&dialog); dialog.show(); - connect(ui.send, SIGNAL(clicked()), SLOT(clicked())); + connect(ui.send, &QPushButton::clicked, this, &Dialog::clicked); } void displayMessage(const QString &message) -- cgit v1.2.1 From 7f992db892686fe4c260b0362d13b957af908692 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Aug 2017 12:57:24 +0200 Subject: Examples: Use canonical include style and sort #include See also https://wiki.qt.io/Writing_Qt_Examples Change-Id: Ife2300b9f1a074e9dc418d53f8c47138129b0cc7 Reviewed-by: Milian Wolff --- examples/webchannel/standalone/main.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'examples/webchannel/standalone/main.cpp') diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index f468652..736ee52 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -48,21 +48,18 @@ ** ****************************************************************************/ -#include "qwebchannel.h" +#include "ui_dialog.h" +#include "../shared/websocketclientwrapper.h" +#include "../shared/websockettransport.h" #include -#include -#include #include -#include +#include #include #include -#include - -#include "../shared/websocketclientwrapper.h" -#include "../shared/websockettransport.h" - -#include "ui_dialog.h" +#include +#include +#include /*! An instance of this class gets published over the WebChannel and is then accessible to HTML clients. -- cgit v1.2.1 From 13294ce605751babad0687e63c033436d129e3d2 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 28 Aug 2017 16:15:18 +0200 Subject: Split up classes in standalone example Change-Id: Ie58e8914415f42b0b4d52106b343e152ba9e7565 Reviewed-by: Milian Wolff --- examples/webchannel/standalone/main.cpp | 75 ++++----------------------------- 1 file changed, 9 insertions(+), 66 deletions(-) (limited to 'examples/webchannel/standalone/main.cpp') diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index 736ee52..3ea66ad 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -48,7 +48,8 @@ ** ****************************************************************************/ -#include "ui_dialog.h" +#include "dialog.h" +#include "core.h" #include "../shared/websocketclientwrapper.h" #include "../shared/websockettransport.h" @@ -61,66 +62,6 @@ #include #include -/*! - 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 = nullptr) - : QObject(parent) - { - ui.setupUi(&dialog); - dialog.show(); - - connect(ui.send, &QPushButton::clicked, this, &Dialog::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; -}; - int main(int argc, char** argv) { QApplication app(argc, argv); @@ -145,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" -- cgit v1.2.1