From 4715ca7bc54fc1f30dd7e603a396c876d667c92c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 3 Feb 2019 17:09:10 +0100 Subject: 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 --- examples/corelib/ipc/localfortuneclient/client.h | 4 +--- examples/corelib/ipc/localfortuneserver/main.cpp | 3 --- examples/corelib/ipc/localfortuneserver/server.cpp | 8 ++----- examples/corelib/ipc/sharedmemory/dialog.cpp | 9 ++++---- examples/corelib/ipc/sharedmemory/dialog.h | 6 ++--- .../corelib/mimetypes/mimetypebrowser/main.cpp | 3 --- .../mimetypes/mimetypebrowser/mimetypemodel.cpp | 3 +-- .../serialization/convert/cborconverter.cpp | 1 - examples/corelib/serialization/savegame/game.cpp | 2 +- examples/corelib/serialization/savegame/level.cpp | 2 +- .../threads/mandelbrot/mandelbrotwidget.cpp | 8 +++---- .../corelib/threads/mandelbrot/mandelbrotwidget.h | 2 +- .../corelib/threads/mandelbrot/renderthread.cpp | 2 +- examples/corelib/threads/mandelbrot/renderthread.h | 2 +- .../corelib/threads/queuedcustomtype/block.cpp | 8 ++----- examples/corelib/threads/queuedcustomtype/block.h | 1 - .../threads/queuedcustomtype/renderthread.h | 2 +- .../corelib/threads/queuedcustomtype/window.cpp | 26 +++++++++++++--------- examples/corelib/threads/queuedcustomtype/window.h | 2 +- .../tools/contiguouscache/randomlistmodel.cpp | 1 - .../tools/contiguouscache/randomlistmodel.h | 2 +- examples/corelib/tools/customtype/main.cpp | 1 + examples/corelib/tools/customtype/message.cpp | 8 +++---- examples/corelib/tools/customtype/message.h | 1 - examples/corelib/tools/customtypesending/main.cpp | 11 ++++----- .../corelib/tools/customtypesending/message.cpp | 6 ++--- examples/corelib/tools/customtypesending/message.h | 1 - .../corelib/tools/customtypesending/window.cpp | 9 ++++---- examples/corelib/tools/customtypesending/window.h | 2 +- 29 files changed, 59 insertions(+), 77 deletions(-) (limited to 'examples') diff --git a/examples/corelib/ipc/localfortuneclient/client.h b/examples/corelib/ipc/localfortuneclient/client.h index 0c1ede94c9..7248428440 100644 --- a/examples/corelib/ipc/localfortuneclient/client.h +++ b/examples/corelib/ipc/localfortuneclient/client.h @@ -53,14 +53,12 @@ #include #include - -#include +#include QT_BEGIN_NAMESPACE class QLabel; class QLineEdit; class QPushButton; -class QLocalSocket; QT_END_NAMESPACE class Client : public QDialog diff --git a/examples/corelib/ipc/localfortuneserver/main.cpp b/examples/corelib/ipc/localfortuneserver/main.cpp index 6f8ec539fe..430005a1d3 100644 --- a/examples/corelib/ipc/localfortuneserver/main.cpp +++ b/examples/corelib/ipc/localfortuneserver/main.cpp @@ -49,9 +49,6 @@ ****************************************************************************/ #include -#include - -#include #include "server.h" diff --git a/examples/corelib/ipc/localfortuneserver/server.cpp b/examples/corelib/ipc/localfortuneserver/server.cpp index be8d4750d6..9be5ed5051 100644 --- a/examples/corelib/ipc/localfortuneserver/server.cpp +++ b/examples/corelib/ipc/localfortuneserver/server.cpp @@ -48,15 +48,11 @@ ** ****************************************************************************/ +#include "server.h" + #include #include -#include - -#include "server.h" -#include -#include - Server::Server(QWidget *parent) : QDialog(parent) { diff --git a/examples/corelib/ipc/sharedmemory/dialog.cpp b/examples/corelib/ipc/sharedmemory/dialog.cpp index ce5a4547bb..4e999d1bcf 100644 --- a/examples/corelib/ipc/sharedmemory/dialog.cpp +++ b/examples/corelib/ipc/sharedmemory/dialog.cpp @@ -51,7 +51,6 @@ #include "dialog.h" #include #include -#include /*! \class Dialog @@ -81,10 +80,10 @@ Dialog::Dialog(QWidget *parent) : QDialog(parent), sharedMemory("QSharedMemoryExample") { ui.setupUi(this); - connect(ui.loadFromFileButton, SIGNAL(clicked()), SLOT(loadFromFile())); - connect(ui.loadFromSharedMemoryButton, - SIGNAL(clicked()), - SLOT(loadFromMemory())); + connect(ui.loadFromFileButton, &QPushButton::clicked, + this, &Dialog::loadFromFile); + connect(ui.loadFromSharedMemoryButton, &QPushButton::clicked, + this, &Dialog::loadFromMemory); setWindowTitle(tr("SharedMemory Example")); } //! [0] diff --git a/examples/corelib/ipc/sharedmemory/dialog.h b/examples/corelib/ipc/sharedmemory/dialog.h index 1662654441..693333256c 100644 --- a/examples/corelib/ipc/sharedmemory/dialog.h +++ b/examples/corelib/ipc/sharedmemory/dialog.h @@ -51,8 +51,8 @@ #ifndef DIALOG_H #define DIALOG_H -#include -#include +#include +#include #include "ui_dialog.h" //! [0] @@ -61,7 +61,7 @@ class Dialog : public QDialog Q_OBJECT public: - Dialog(QWidget *parent = 0); + Dialog(QWidget *parent = nullptr); public slots: void loadFromFile(); diff --git a/examples/corelib/mimetypes/mimetypebrowser/main.cpp b/examples/corelib/mimetypes/mimetypebrowser/main.cpp index f4462df411..cf87004a01 100644 --- a/examples/corelib/mimetypes/mimetypebrowser/main.cpp +++ b/examples/corelib/mimetypes/mimetypebrowser/main.cpp @@ -55,9 +55,6 @@ #include #include -#include -#include -#include int main(int argc, char *argv[]) { diff --git a/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.cpp b/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.cpp index ee83de092d..f755e060c6 100644 --- a/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.cpp +++ b/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.cpp @@ -50,9 +50,8 @@ #include "mimetypemodel.h" -#include - #include +#include #include #include #include diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp index f906c81062..ad69983eb1 100644 --- a/examples/corelib/serialization/convert/cborconverter.cpp +++ b/examples/corelib/serialization/convert/cborconverter.cpp @@ -56,7 +56,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/corelib/serialization/savegame/game.cpp b/examples/corelib/serialization/savegame/game.cpp index 226f6fda11..c39362bc68 100644 --- a/examples/corelib/serialization/savegame/game.cpp +++ b/examples/corelib/serialization/savegame/game.cpp @@ -185,7 +185,7 @@ void Game::write(QJsonObject &json) const json["player"] = playerObject; QJsonArray levelArray; - for (const Level level : mLevels) { + for (const Level &level : mLevels) { QJsonObject levelObject; level.write(levelObject); levelArray.append(levelObject); diff --git a/examples/corelib/serialization/savegame/level.cpp b/examples/corelib/serialization/savegame/level.cpp index c7adc6c8ff..6fe46e8938 100644 --- a/examples/corelib/serialization/savegame/level.cpp +++ b/examples/corelib/serialization/savegame/level.cpp @@ -97,7 +97,7 @@ void Level::write(QJsonObject &json) const { json["name"] = mName; QJsonArray npcArray; - for (const Character npc : mNpcs) { + for (const Character &npc : mNpcs) { QJsonObject npcObject; npc.write(npcObject); npcArray.append(npcObject); diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp index b3e4af5dc8..2603f041b2 100644 --- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp +++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp @@ -48,14 +48,13 @@ ** ****************************************************************************/ +#include "mandelbrotwidget.h" + #include #include #include -#include "mandelbrotwidget.h" - - //! [0] const double DefaultCenterX = -0.637011f; const double DefaultCenterY = -0.0395159f; @@ -75,7 +74,8 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) pixmapScale = DefaultScale; curScale = DefaultScale; - connect(&thread, SIGNAL(renderedImage(QImage,double)), this, SLOT(updatePixmap(QImage,double))); + connect(&thread, &RenderThread::renderedImage, + this, &MandelbrotWidget::updatePixmap); setWindowTitle(tr("Mandelbrot")); #ifndef QT_NO_CURSOR diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h index a04bfa6e81..cb40962535 100644 --- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h +++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h @@ -62,7 +62,7 @@ class MandelbrotWidget : public QWidget Q_OBJECT public: - MandelbrotWidget(QWidget *parent = 0); + MandelbrotWidget(QWidget *parent = nullptr); protected: void paintEvent(QPaintEvent *event) override; diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp index c57b696e25..eee44c7242 100644 --- a/examples/corelib/threads/mandelbrot/renderthread.cpp +++ b/examples/corelib/threads/mandelbrot/renderthread.cpp @@ -50,7 +50,7 @@ #include "renderthread.h" -#include +#include #include //! [0] diff --git a/examples/corelib/threads/mandelbrot/renderthread.h b/examples/corelib/threads/mandelbrot/renderthread.h index b5e9226fb8..4f0394d554 100644 --- a/examples/corelib/threads/mandelbrot/renderthread.h +++ b/examples/corelib/threads/mandelbrot/renderthread.h @@ -66,7 +66,7 @@ class RenderThread : public QThread Q_OBJECT public: - RenderThread(QObject *parent = 0); + RenderThread(QObject *parent = nullptr); ~RenderThread(); void render(double centerX, double centerY, double scaleFactor, QSize resultSize); diff --git a/examples/corelib/threads/queuedcustomtype/block.cpp b/examples/corelib/threads/queuedcustomtype/block.cpp index a5058cc5ae..9cfad8673c 100644 --- a/examples/corelib/threads/queuedcustomtype/block.cpp +++ b/examples/corelib/threads/queuedcustomtype/block.cpp @@ -48,8 +48,6 @@ ** ****************************************************************************/ -#include -#include #include "block.h" Block::Block() @@ -57,9 +55,8 @@ Block::Block() } Block::Block(const Block &other) + : m_rect(other.m_rect), m_color(other.m_color) { - m_rect = other.m_rect; - m_color = other.m_color; } Block::~Block() @@ -67,9 +64,8 @@ Block::~Block() } Block::Block(const QRect &rect, const QColor &color) + : m_rect(rect), m_color(color) { - m_rect = rect; - m_color = color; } QColor Block::color() const diff --git a/examples/corelib/threads/queuedcustomtype/block.h b/examples/corelib/threads/queuedcustomtype/block.h index 547cc10f0a..eef48b25c2 100644 --- a/examples/corelib/threads/queuedcustomtype/block.h +++ b/examples/corelib/threads/queuedcustomtype/block.h @@ -52,7 +52,6 @@ #define BLOCK_H #include -#include #include #include diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.h b/examples/corelib/threads/queuedcustomtype/renderthread.h index 318ef293b4..9375b60e74 100644 --- a/examples/corelib/threads/queuedcustomtype/renderthread.h +++ b/examples/corelib/threads/queuedcustomtype/renderthread.h @@ -62,7 +62,7 @@ class RenderThread : public QThread Q_OBJECT public: - RenderThread(QObject *parent = 0); + RenderThread(QObject *parent = nullptr); ~RenderThread(); void processImage(const QImage &image); diff --git a/examples/corelib/threads/queuedcustomtype/window.cpp b/examples/corelib/threads/queuedcustomtype/window.cpp index 0d3f80aba4..183d9824cb 100644 --- a/examples/corelib/threads/queuedcustomtype/window.cpp +++ b/examples/corelib/threads/queuedcustomtype/window.cpp @@ -48,30 +48,34 @@ ** ****************************************************************************/ -#include #include "window.h" +#include //! [Window constructor start] -Window::Window() +Window::Window(QWidget *parent) + : QWidget(parent), thread(new RenderThread(this)) { - thread = new RenderThread(); //! [Window constructor start] //! [set up widgets and connections] - label = new QLabel(); + label = new QLabel(this); label->setAlignment(Qt::AlignCenter); - loadButton = new QPushButton(tr("&Load image...")); - resetButton = new QPushButton(tr("&Stop")); + loadButton = new QPushButton(tr("&Load image..."), this); + resetButton = new QPushButton(tr("&Stop"), this); resetButton->setEnabled(false); - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadImage())); - connect(resetButton, SIGNAL(clicked()), thread, SLOT(stopProcess())); - connect(thread, SIGNAL(finished()), this, SLOT(resetUi())); + connect(loadButton, &QPushButton::clicked, + this, QOverload<>::of(&Window::loadImage)); + connect(resetButton, &QPushButton::clicked, + thread, &RenderThread::stopProcess); + connect(thread, &RenderThread::finished, + this, &Window::resetUi); //! [set up widgets and connections] //! [connecting signal with custom type] - connect(thread, SIGNAL(sendBlock(Block)), this, SLOT(addBlock(Block))); + connect(thread, &RenderThread::sendBlock, + this, &Window::addBlock); //! [connecting signal with custom type] - QHBoxLayout *buttonLayout = new QHBoxLayout(); + QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(); buttonLayout->addWidget(loadButton); buttonLayout->addWidget(resetButton); diff --git a/examples/corelib/threads/queuedcustomtype/window.h b/examples/corelib/threads/queuedcustomtype/window.h index c472c0fea7..4215dfd5a7 100644 --- a/examples/corelib/threads/queuedcustomtype/window.h +++ b/examples/corelib/threads/queuedcustomtype/window.h @@ -65,7 +65,7 @@ class Window : public QWidget Q_OBJECT public: - Window(); + Window(QWidget *parent = nullptr); void loadImage(const QImage &image); public slots: diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp index ccaa45a28b..d028b896f2 100644 --- a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp +++ b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp @@ -49,7 +49,6 @@ ****************************************************************************/ #include "randomlistmodel.h" #include -#include static const int bufferSize(500); static const int lookAhead(100); diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.h b/examples/corelib/tools/contiguouscache/randomlistmodel.h index e6192b434f..1fabb0d9f5 100644 --- a/examples/corelib/tools/contiguouscache/randomlistmodel.h +++ b/examples/corelib/tools/contiguouscache/randomlistmodel.h @@ -59,7 +59,7 @@ class RandomListModel : public QAbstractListModel { Q_OBJECT public: - RandomListModel(QObject *parent = 0); + RandomListModel(QObject *parent = nullptr); ~RandomListModel(); int rowCount(const QModelIndex & = QModelIndex()) const override; diff --git a/examples/corelib/tools/customtype/main.cpp b/examples/corelib/tools/customtype/main.cpp index ced317e208..d50bf9efea 100644 --- a/examples/corelib/tools/customtype/main.cpp +++ b/examples/corelib/tools/customtype/main.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include +#include #include #include "message.h" diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp index 8b2c295e46..cc96aee978 100644 --- a/examples/corelib/tools/customtype/message.cpp +++ b/examples/corelib/tools/customtype/message.cpp @@ -50,15 +50,16 @@ #include "message.h" +#include + //! [Message class implementation] 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() @@ -67,9 +68,8 @@ Message::~Message() //! [Message class implementation] Message::Message(const QString &body, const QStringList &headers) + : m_body(body), m_headers(headers) { - m_body = body; - m_headers = headers; } //! [custom type streaming operator] diff --git a/examples/corelib/tools/customtype/message.h b/examples/corelib/tools/customtype/message.h index 9871a7d52d..c1b8243237 100644 --- a/examples/corelib/tools/customtype/message.h +++ b/examples/corelib/tools/customtype/message.h @@ -51,7 +51,6 @@ #ifndef MESSAGE_H #define MESSAGE_H -#include #include #include 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 #include #include 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); -- cgit v1.2.3