diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-02-03 17:09:10 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2019-02-06 22:11:27 +0000 |
commit | 4715ca7bc54fc1f30dd7e603a396c876d667c92c (patch) | |
tree | c18936b1b194f7820dfbe5c74214f252ec0a10e6 /examples/corelib/tools/customtypesending | |
parent | 7910dd0a548cdd9e7c5716d4f6704b3185fa34fb (diff) |
Cleanup QtCore examples
Cleanup QtCore examples:
- use new signal/slot syntax
- use 0 instead nullptr
- remove unneeded includes
- use initializer lists
- replace foreach with range-based-for loop
Change-Id: I5581f485fa0e9ccf3f4ce6f643908832bc6959bb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'examples/corelib/tools/customtypesending')
5 files changed, 14 insertions, 15 deletions
diff --git a/examples/corelib/tools/customtypesending/main.cpp b/examples/corelib/tools/customtypesending/main.cpp index 966c284d9a..c5d643b9d1 100644 --- a/examples/corelib/tools/customtypesending/main.cpp +++ b/examples/corelib/tools/customtypesending/main.cpp @@ -57,19 +57,20 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - Window window1; QStringList headers; headers << "Subject: Hello World" << "From: address@example.com"; QString body = "This is a test.\r\n"; Message message(body, headers); + + Window window1; window1.setMessage(message); Window window2; - QObject::connect(&window1, SIGNAL(messageSent(Message)), - &window2, SLOT(setMessage(Message))); - QObject::connect(&window2, SIGNAL(messageSent(Message)), - &window1, SLOT(setMessage(Message))); + QObject::connect(&window1, &Window::messageSent, + &window2, &Window::setMessage); + QObject::connect(&window2, &Window::messageSent, + &window1, &Window::setMessage); window1.show(); window2.show(); return app.exec(); diff --git a/examples/corelib/tools/customtypesending/message.cpp b/examples/corelib/tools/customtypesending/message.cpp index c990768079..9386b93898 100644 --- a/examples/corelib/tools/customtypesending/message.cpp +++ b/examples/corelib/tools/customtypesending/message.cpp @@ -55,9 +55,8 @@ Message::Message() } Message::Message(const Message &other) + : m_body(other.m_body), m_headers(other.m_headers) { - m_body = other.m_body; - m_headers = other.m_headers; } Message::~Message() @@ -65,9 +64,8 @@ Message::~Message() } Message::Message(const QString &body, const QStringList &headers) + : m_body(body), m_headers(headers) { - m_body = body; - m_headers = headers; } QString Message::body() const diff --git a/examples/corelib/tools/customtypesending/message.h b/examples/corelib/tools/customtypesending/message.h index a8d6d6be05..a93f111e45 100644 --- a/examples/corelib/tools/customtypesending/message.h +++ b/examples/corelib/tools/customtypesending/message.h @@ -51,7 +51,6 @@ #ifndef MESSAGE_H #define MESSAGE_H -#include <QDebug> #include <QMetaType> #include <QStringList> diff --git a/examples/corelib/tools/customtypesending/window.cpp b/examples/corelib/tools/customtypesending/window.cpp index 224656f94c..db4b52a985 100644 --- a/examples/corelib/tools/customtypesending/window.cpp +++ b/examples/corelib/tools/customtypesending/window.cpp @@ -52,14 +52,15 @@ #include "window.h" //! [Window constructor] -Window::Window() +Window::Window(QWidget *parent) + : QWidget(parent), editor(new QTextEdit(this)) { - editor = new QTextEdit(); QPushButton *sendButton = new QPushButton(tr("&Send message")); - connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage())); + connect(sendButton, &QPushButton::clicked, + this, &Window::sendMessage); - QHBoxLayout *buttonLayout = new QHBoxLayout(); + QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(); buttonLayout->addWidget(sendButton); buttonLayout->addStretch(); diff --git a/examples/corelib/tools/customtypesending/window.h b/examples/corelib/tools/customtypesending/window.h index d050931b74..048fecef67 100644 --- a/examples/corelib/tools/customtypesending/window.h +++ b/examples/corelib/tools/customtypesending/window.h @@ -62,7 +62,7 @@ class Window : public QWidget Q_OBJECT public: - Window(); + Window(QWidget *parent = nullptr); signals: void messageSent(const Message &message); |