summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/embedded/flickable/flickable.cpp10
-rw-r--r--examples/embedded/raycasting/raycasting.cpp8
-rw-r--r--examples/gui/openglwindow/main.cpp49
-rw-r--r--examples/gui/openglwindow/openglwindow.cpp11
-rw-r--r--examples/gui/openglwindow/openglwindow.h12
-rw-r--r--examples/network/bearermonitor/bearermonitor.cpp53
-rw-r--r--examples/network/bearermonitor/bearermonitor.h9
-rw-r--r--examples/network/bearermonitor/main.cpp4
-rw-r--r--examples/network/bearermonitor/sessionwidget.cpp28
-rw-r--r--examples/network/bearermonitor/sessionwidget.h10
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.cpp39
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.h2
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.h2
-rw-r--r--examples/network/broadcastreceiver/receiver.cpp13
-rw-r--r--examples/network/dnslookup/dnslookup.cpp4
-rw-r--r--examples/network/doc/src/blockingfortuneclient.qdoc7
-rw-r--r--examples/network/download/main.cpp8
-rw-r--r--examples/network/downloadmanager/downloadmanager.cpp16
-rw-r--r--examples/network/downloadmanager/main.cpp3
-rw-r--r--examples/network/googlesuggest/googlesuggest.cpp16
-rw-r--r--examples/network/googlesuggest/searchbox.cpp8
-rw-r--r--examples/network/multicastreceiver/receiver.cpp10
-rw-r--r--examples/network/multistreamclient/client.cpp4
-rw-r--r--examples/network/network-chat/chatdialog.cpp16
-rw-r--r--examples/network/network-chat/chatdialog.h2
-rw-r--r--examples/network/network-chat/client.cpp20
-rw-r--r--examples/network/network-chat/connection.cpp13
-rw-r--r--examples/network/network-chat/connection.h4
-rw-r--r--examples/network/network-chat/peermanager.cpp8
-rw-r--r--examples/network/network-chat/server.h2
-rw-r--r--examples/network/securesocketclient/main.cpp4
-rw-r--r--examples/network/securesocketclient/sslclient.cpp37
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp2
-rw-r--r--examples/network/threadedfortuneserver/dialog.h2
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.cpp2
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.h2
-rw-r--r--examples/network/torrent/addtorrentdialog.cpp12
-rw-r--r--examples/network/torrent/addtorrentdialog.h2
-rw-r--r--examples/network/torrent/filemanager.h2
-rw-r--r--examples/network/torrent/mainwindow.cpp92
-rw-r--r--examples/network/torrent/mainwindow.h2
-rw-r--r--examples/network/torrent/peerwireclient.cpp34
-rw-r--r--examples/network/torrent/peerwireclient.h2
-rw-r--r--examples/network/torrent/ratecontroller.cpp6
-rw-r--r--examples/network/torrent/ratecontroller.h9
-rw-r--r--examples/network/torrent/torrentclient.cpp88
-rw-r--r--examples/network/torrent/torrentclient.h5
-rw-r--r--examples/network/torrent/torrentserver.cpp10
-rw-r--r--examples/network/torrent/trackerclient.cpp14
-rw-r--r--examples/network/torrent/trackerclient.h16
-rw-r--r--examples/opengl/computegles31/glwindow.cpp39
-rw-r--r--examples/opengl/computegles31/glwindow.h22
-rw-r--r--examples/opengl/contextinfo/renderwindow.cpp4
-rw-r--r--examples/opengl/contextinfo/widget.h2
-rw-r--r--examples/opengl/cube/geometryengine.cpp2
-rw-r--r--examples/opengl/cube/mainwidget.cpp10
-rw-r--r--examples/opengl/cube/mainwidget.h8
-rw-r--r--examples/opengl/hellogl2/glwidget.cpp14
-rw-r--r--examples/opengl/hellogl2/glwidget.h18
-rw-r--r--examples/opengl/hellogl2/logo.cpp1
-rw-r--r--examples/opengl/hellogl2/logo.h2
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp3
-rw-r--r--examples/opengl/hellogl2/window.cpp8
-rw-r--r--examples/opengl/hellogles3/glwindow.cpp32
-rw-r--r--examples/opengl/hellogles3/glwindow.h26
-rw-r--r--examples/opengl/qopenglwidget/bubble.cpp7
-rw-r--r--examples/opengl/qopenglwidget/bubble.h2
-rw-r--r--examples/opengl/qopenglwidget/glwidget.cpp8
-rw-r--r--examples/opengl/qopenglwidget/glwidget.h46
-rw-r--r--examples/opengl/textures/glwidget.cpp11
-rw-r--r--examples/opengl/textures/glwidget.h14
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp7
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h18
-rw-r--r--examples/sql/masterdetail/mainwindow.cpp2
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp2
-rw-r--r--examples/widgets/doc/dropsite.qdoc12
-rw-r--r--examples/widgets/doc/src/icons.qdoc38
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp21
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.h2
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h2
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp2
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h4
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.cpp2
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h2
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h2
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp5
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h6
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp28
88 files changed, 545 insertions, 623 deletions
diff --git a/examples/embedded/flickable/flickable.cpp b/examples/embedded/flickable/flickable.cpp
index fff4bac0e6..c57ec3d111 100644
--- a/examples/embedded/flickable/flickable.cpp
+++ b/examples/embedded/flickable/flickable.cpp
@@ -98,7 +98,7 @@ public:
QPoint delta;
QPoint speed;
FlickableTicker *ticker;
- QTime timeStamp;
+ QElapsedTimer timeStamp;
QWidget *target;
QList<QEvent*> ignoreList;
};
@@ -109,7 +109,7 @@ Flickable::Flickable()
d->state = FlickablePrivate::Steady;
d->threshold = 10;
d->ticker = new FlickableTicker(this);
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->target = 0;
}
@@ -208,7 +208,7 @@ void Flickable::handleMouseRelease(QMouseEvent *event)
event->accept();
delta = event->pos() - d->pressPos;
if (d->timeStamp.elapsed() > 100) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}
@@ -253,7 +253,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
if (delta.x() > d->threshold || delta.x() < -d->threshold ||
delta.y() > d->threshold || delta.y() < -d->threshold) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->state = FlickablePrivate::ManualScroll;
d->delta = QPoint(0, 0);
d->pressPos = event->pos();
@@ -266,7 +266,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
setScrollOffset(d->offset - delta);
if (d->timeStamp.elapsed() > 100) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}
diff --git a/examples/embedded/raycasting/raycasting.cpp b/examples/embedded/raycasting/raycasting.cpp
index 7213811213..c0a1e48fa6 100644
--- a/examples/embedded/raycasting/raycasting.cpp
+++ b/examples/embedded/raycasting/raycasting.cpp
@@ -92,7 +92,7 @@ public:
}
void updatePlayer() {
- int interval = qBound(20, watch.elapsed(), 250);
+ int interval = qBound(20ll, watch.elapsed(), 250ll);
watch.start();
angle += angleDelta * interval / 1000;
qreal step = moveDelta * interval / 1000;
@@ -106,10 +106,10 @@ public:
}
void showFps() {
- static QTime frameTick;
+ static QElapsedTimer frameTick;
static int totalFrame = 0;
if (!(totalFrame & 31)) {
- int elapsed = frameTick.elapsed();
+ const qint64 elapsed = frameTick.elapsed();
frameTick.start();
int fps = 32 * 1000 / (1 + elapsed);
setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps));
@@ -355,7 +355,7 @@ protected:
}
private:
- QTime watch;
+ QElapsedTimer watch;
QBasicTimer ticker;
QImage buffer;
qreal angle;
diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp
index 90c93f0d37..03a6ece06f 100644
--- a/examples/gui/openglwindow/main.cpp
+++ b/examples/gui/openglwindow/main.cpp
@@ -50,36 +50,30 @@
#include "openglwindow.h"
-#include <QtGui/QGuiApplication>
-#include <QtGui/QMatrix4x4>
-#include <QtGui/QOpenGLShaderProgram>
-#include <QtGui/QScreen>
+#include <QGuiApplication>
+#include <QMatrix4x4>
+#include <QOpenGLShaderProgram>
+#include <QScreen>
+#include <QtMath>
-#include <QtCore/qmath.h>
//! [1]
class TriangleWindow : public OpenGLWindow
{
public:
- TriangleWindow();
+ using OpenGLWindow::OpenGLWindow;
void initialize() override;
void render() override;
private:
- GLuint m_posAttr;
- GLuint m_colAttr;
- GLuint m_matrixUniform;
+ GLint m_posAttr = 0;
+ GLint m_colAttr = 0;
+ GLint m_matrixUniform = 0;
- QOpenGLShaderProgram *m_program;
- int m_frame;
+ QOpenGLShaderProgram *m_program = nullptr;
+ int m_frame = 0;
};
-
-TriangleWindow::TriangleWindow()
- : m_program(0)
- , m_frame(0)
-{
-}
//! [1]
//! [2]
@@ -128,8 +122,11 @@ void TriangleWindow::initialize()
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link();
m_posAttr = m_program->attributeLocation("posAttr");
+ Q_ASSERT(m_posAttr != -1);
m_colAttr = m_program->attributeLocation("colAttr");
+ Q_ASSERT(m_colAttr != -1);
m_matrixUniform = m_program->uniformLocation("matrix");
+ Q_ASSERT(m_matrixUniform != -1);
}
//! [4]
@@ -144,19 +141,19 @@ void TriangleWindow::render()
m_program->bind();
QMatrix4x4 matrix;
- matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f);
+ matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
matrix.translate(0, 0, -2);
matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
m_program->setUniformValue(m_matrixUniform, matrix);
- GLfloat vertices[] = {
- 0.0f, 0.707f,
+ static const GLfloat vertices[] = {
+ 0.0f, 0.707f,
-0.5f, -0.5f,
- 0.5f, -0.5f
+ 0.5f, -0.5f
};
- GLfloat colors[] = {
+ static const GLfloat colors[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
@@ -165,13 +162,13 @@ void TriangleWindow::render()
glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
+ glEnableVertexAttribArray(m_posAttr);
+ glEnableVertexAttribArray(m_colAttr);
glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(1);
- glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(m_colAttr);
+ glDisableVertexAttribArray(m_posAttr);
m_program->release();
diff --git a/examples/gui/openglwindow/openglwindow.cpp b/examples/gui/openglwindow/openglwindow.cpp
index a0c85006bd..bac887dca0 100644
--- a/examples/gui/openglwindow/openglwindow.cpp
+++ b/examples/gui/openglwindow/openglwindow.cpp
@@ -50,18 +50,13 @@
#include "openglwindow.h"
-#include <QtCore/QCoreApplication>
-
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLPaintDevice>
-#include <QtGui/QPainter>
+#include <QOpenGLContext>
+#include <QOpenGLPaintDevice>
+#include <QPainter>
//! [1]
OpenGLWindow::OpenGLWindow(QWindow *parent)
: QWindow(parent)
- , m_animating(false)
- , m_context(0)
- , m_device(0)
{
setSurfaceType(QWindow::OpenGLSurface);
}
diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h
index 6e6c1d7449..8db943ddde 100644
--- a/examples/gui/openglwindow/openglwindow.h
+++ b/examples/gui/openglwindow/openglwindow.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include <QtGui/QWindow>
-#include <QtGui/QOpenGLFunctions>
+#include <QWindow>
+#include <QOpenGLFunctions>
QT_BEGIN_NAMESPACE
class QPainter;
@@ -62,7 +62,7 @@ class OpenGLWindow : public QWindow, protected QOpenGLFunctions
{
Q_OBJECT
public:
- explicit OpenGLWindow(QWindow *parent = 0);
+ explicit OpenGLWindow(QWindow *parent = nullptr);
~OpenGLWindow();
virtual void render(QPainter *painter);
@@ -82,10 +82,10 @@ protected:
void exposeEvent(QExposeEvent *event) override;
private:
- bool m_animating;
+ bool m_animating = false;
- QOpenGLContext *m_context;
- QOpenGLPaintDevice *m_device;
+ QOpenGLContext *m_context = nullptr;
+ QOpenGLPaintDevice *m_device = nullptr;
};
//! [1]
diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp
index 1a54f5ec8a..322224a902 100644
--- a/examples/network/bearermonitor/bearermonitor.cpp
+++ b/examples/network/bearermonitor/bearermonitor.cpp
@@ -80,34 +80,37 @@ BearerMonitor::BearerMonitor(QWidget *parent)
break;
}
}
- connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool)));
- connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
- this, SLOT(configurationAdded(const QNetworkConfiguration&)));
- connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
- this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
- connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
- this, SLOT(configurationChanged(const QNetworkConfiguration)));
- connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations()));
+ connect(&manager, &QNetworkConfigurationManager::onlineStateChanged,
+ this, &BearerMonitor::onlineStateChanged);
+ connect(&manager, &QNetworkConfigurationManager::configurationAdded,
+ this, [this](const QNetworkConfiguration &config) { configurationAdded(config); });
+ connect(&manager, &QNetworkConfigurationManager::configurationRemoved,
+ this, &BearerMonitor::configurationRemoved);
+ connect(&manager, &QNetworkConfigurationManager::configurationChanged,
+ this, &BearerMonitor::configurationChanged);
+ connect(&manager, &QNetworkConfigurationManager::updateCompleted,
+ this, &BearerMonitor::updateConfigurations);
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
- connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork()));
- connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork()));
+ connect(registerButton, &QPushButton::clicked,
+ this, &BearerMonitor::registerNetwork);
+ connect(unregisterButton, &QPushButton::clicked,
+ this, &BearerMonitor::unregisterNetwork);
#else // Q_OS_WIN && !Q_OS_WINRT
nlaGroup->hide();
#endif
- connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
- this, SLOT(createSessionFor(QTreeWidgetItem*)));
+ connect(treeWidget, &QTreeWidget::itemActivated,
+ this, &BearerMonitor::createSessionFor);
+ connect(treeWidget, &QTreeWidget::currentItemChanged,
+ this, &BearerMonitor::showConfigurationFor);
- connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
- this, SLOT(showConfigurationFor(QTreeWidgetItem*)));
-
- connect(newSessionButton, SIGNAL(clicked()),
- this, SLOT(createNewSession()));
- connect(deleteSessionButton, SIGNAL(clicked()),
- this, SLOT(deleteSession()));
- connect(scanButton, SIGNAL(clicked()),
- this, SLOT(performScan()));
+ connect(newSessionButton, &QPushButton::clicked,
+ this, &BearerMonitor::createNewSession);
+ connect(deleteSessionButton, &QPushButton::clicked,
+ this, &BearerMonitor::deleteSession);
+ connect(scanButton, &QPushButton::clicked,
+ this, &BearerMonitor::performScan);
// Just in case update all configurations so that all
// configurations are up to date.
@@ -124,7 +127,7 @@ static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &confi
item->setData(0, Qt::UserRole, config.identifier());
QFont font = item->font(1);
- font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active);
+ font.setBold(config.state().testFlag(QNetworkConfiguration::Active));
item->setFont(0, font);
}
@@ -333,8 +336,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
case QNetworkConfiguration::Undefined:
configurationState->setText(tr("Undefined"));
break;
- default:
- configurationState->setText(QString());
}
switch (conf.type()) {
@@ -350,8 +351,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
case QNetworkConfiguration::Invalid:
configurationType->setText(tr("Invalid"));
break;
- default:
- configurationType->setText(QString());
}
switch (conf.purpose()) {
@@ -367,8 +366,6 @@ void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
case QNetworkConfiguration::ServiceSpecificPurpose:
configurationPurpose->setText(tr("Service Specific"));
break;
- default:
- configurationPurpose->setText(QString());
}
configurationIdentifier->setText(conf.identifier());
diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h
index 7de186cd14..79b8d876ec 100644
--- a/examples/network/bearermonitor/bearermonitor.h
+++ b/examples/network/bearermonitor/bearermonitor.h
@@ -51,8 +51,7 @@
#ifndef BEARERMONITOR_H
#define BEARERMONITOR_H
-#include <qnetworkconfigmanager.h>
-#include <qnetworksession.h>
+#include <QNetworkConfigurationManager>
#include "ui_bearermonitor_640_480.h"
QT_USE_NAMESPACE
@@ -64,11 +63,11 @@ class BearerMonitor : public QWidget, public Ui_BearerMonitor
Q_OBJECT
public:
- BearerMonitor(QWidget *parent = 0);
+ BearerMonitor(QWidget *parent = nullptr);
~BearerMonitor();
private slots:
- void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0);
+ void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = nullptr);
void configurationRemoved(const QNetworkConfiguration &config);
void configurationChanged(const QNetworkConfiguration &config);
void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap);
@@ -90,7 +89,7 @@ private slots:
private:
QNetworkConfigurationManager manager;
- QList<SessionWidget *> sessionWidgets;
+ QVector<SessionWidget *> sessionWidgets;
};
#endif //BEARERMONITOR_H
diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp
index 363889dee4..3c2525012d 100644
--- a/examples/network/bearermonitor/main.cpp
+++ b/examples/network/bearermonitor/main.cpp
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMainWindow>
+#include <QApplication>
+#include <QMainWindow>
#include "bearermonitor.h"
diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp
index 237ceee2bd..0fd5d4f67f 100644
--- a/examples/network/bearermonitor/sessionwidget.cpp
+++ b/examples/network/bearermonitor/sessionwidget.cpp
@@ -49,10 +49,10 @@
****************************************************************************/
#include "sessionwidget.h"
-#include "qnetworkconfigmanager.h"
+#include <QNetworkConfigurationManager>
SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent)
-: QWidget(parent), statsTimer(-1)
+: QWidget(parent)
{
setupUi(this);
@@ -65,10 +65,10 @@ SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *paren
session = new QNetworkSession(config, this);
- connect(session, SIGNAL(stateChanged(QNetworkSession::State)),
- this, SLOT(updateSession()));
- connect(session, SIGNAL(error(QNetworkSession::SessionError)),
- this, SLOT(updateSessionError(QNetworkSession::SessionError)));
+ connect(session, &QNetworkSession::stateChanged,
+ this, &SessionWidget::updateSession);
+ connect(session, QOverload<QNetworkSession::SessionError>::of(&QNetworkSession::error),
+ this, &SessionWidget::updateSessionError);
updateSession();
@@ -76,14 +76,14 @@ SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *paren
configuration->setText(session->configuration().name());
- connect(openSessionButton, SIGNAL(clicked()),
- this, SLOT(openSession()));
- connect(openSyncSessionButton, SIGNAL(clicked()),
- this, SLOT(openSyncSession()));
- connect(closeSessionButton, SIGNAL(clicked()),
- this, SLOT(closeSession()));
- connect(stopSessionButton, SIGNAL(clicked()),
- this, SLOT(stopSession()));
+ connect(openSessionButton, &QPushButton::clicked,
+ this, &SessionWidget::openSession);
+ connect(openSyncSessionButton, &QPushButton::clicked,
+ this, &SessionWidget::openSyncSession);
+ connect(closeSessionButton, &QPushButton::clicked,
+ this, &SessionWidget::closeSession);
+ connect(stopSessionButton, &QPushButton::clicked,
+ this, &SessionWidget::stopSession);
}
SessionWidget::~SessionWidget()
diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h
index ba352eefee..6b2da2c1c1 100644
--- a/examples/network/bearermonitor/sessionwidget.h
+++ b/examples/network/bearermonitor/sessionwidget.h
@@ -51,7 +51,7 @@
#ifndef SESSIONWIDGET_H
#define SESSIONWIDGET_H
-#include <qnetworksession.h>
+#include <QNetworkSession>
#include "ui_sessionwidget.h"
@@ -62,10 +62,10 @@ class SessionWidget : public QWidget, public Ui_SessionWidget
Q_OBJECT
public:
- explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0);
+ explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = nullptr);
~SessionWidget();
- void timerEvent(QTimerEvent *) override;
+ void timerEvent(QTimerEvent *e) override;
private:
void updateSessionState(QNetworkSession::State state);
@@ -80,8 +80,8 @@ private Q_SLOTS:
void updateSessionError(QNetworkSession::SessionError error);
private:
- QNetworkSession *session;
- int statsTimer;
+ QNetworkSession *session = nullptr;
+ int statsTimer = -1;
};
#endif
diff --git a/examples/network/blockingfortuneclient/blockingclient.cpp b/examples/network/blockingfortuneclient/blockingclient.cpp
index 607215cf13..5a1500d084 100644
--- a/examples/network/blockingfortuneclient/blockingclient.cpp
+++ b/examples/network/blockingfortuneclient/blockingclient.cpp
@@ -96,20 +96,21 @@ BlockingClient::BlockingClient(QWidget *parent)
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
- connect(getFortuneButton, SIGNAL(clicked()), this, SLOT(requestNewFortune()));
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
-
- connect(hostLineEdit, SIGNAL(textChanged(QString)),
- this, SLOT(enableGetFortuneButton()));
- connect(portLineEdit, SIGNAL(textChanged(QString)),
- this, SLOT(enableGetFortuneButton()));
+ connect(getFortuneButton, &QPushButton::clicked,
+ this, &BlockingClient::requestNewFortune);
+ connect(quitButton, &QPushButton::clicked,
+ this, &BlockingClient::close);
+
+ connect(hostLineEdit, &QLineEdit::textChanged,
+ this, &BlockingClient::enableGetFortuneButton);
+ connect(portLineEdit, &QLineEdit::textChanged,
+ this, &BlockingClient::enableGetFortuneButton);
+//! [0]
+ connect(&thread, &FortuneThread::newFortune,
+ this, &BlockingClient::showFortune);
+ connect(&thread, &FortuneThread::error,
+ this, &BlockingClient::displayError);
//! [0]
- connect(&thread, SIGNAL(newFortune(QString)),
- this, SLOT(showFortune(QString)));
-//! [0] //! [1]
- connect(&thread, SIGNAL(error(int,QString)),
- this, SLOT(displayError(int,QString)));
-//! [1]
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(hostLabel, 0, 0);
@@ -124,30 +125,30 @@ BlockingClient::BlockingClient(QWidget *parent)
portLineEdit->setFocus();
}
-//! [2]
+//! [1]
void BlockingClient::requestNewFortune()
{
getFortuneButton->setEnabled(false);
thread.requestNewFortune(hostLineEdit->text(),
portLineEdit->text().toInt());
}
-//! [2]
+//! [1]
-//! [3]
+//! [2]
void BlockingClient::showFortune(const QString &nextFortune)
{
if (nextFortune == currentFortune) {
requestNewFortune();
return;
}
-//! [3]
+//! [2]
-//! [4]
+//! [3]
currentFortune = nextFortune;
statusLabel->setText(currentFortune);
getFortuneButton->setEnabled(true);
}
-//! [4]
+//! [3]
void BlockingClient::displayError(int socketError, const QString &message)
{
diff --git a/examples/network/blockingfortuneclient/blockingclient.h b/examples/network/blockingfortuneclient/blockingclient.h
index 2a2dd81b71..b8a7163160 100644
--- a/examples/network/blockingfortuneclient/blockingclient.h
+++ b/examples/network/blockingfortuneclient/blockingclient.h
@@ -69,7 +69,7 @@ class BlockingClient : public QWidget
Q_OBJECT
public:
- BlockingClient(QWidget *parent = 0);
+ BlockingClient(QWidget *parent = nullptr);
private slots:
void requestNewFortune();
diff --git a/examples/network/blockingfortuneclient/fortunethread.h b/examples/network/blockingfortuneclient/fortunethread.h
index 0cbc3961fc..b6b63d9319 100644
--- a/examples/network/blockingfortuneclient/fortunethread.h
+++ b/examples/network/blockingfortuneclient/fortunethread.h
@@ -61,7 +61,7 @@ class FortuneThread : public QThread
Q_OBJECT
public:
- FortuneThread(QObject *parent = 0);
+ FortuneThread(QObject *parent = nullptr);
~FortuneThread();
void requestNewFortune(const QString &hostName, quint16 port);
diff --git a/examples/network/broadcastreceiver/receiver.cpp b/examples/network/broadcastreceiver/receiver.cpp
index 2f111b4795..5b932a27b9 100644
--- a/examples/network/broadcastreceiver/receiver.cpp
+++ b/examples/network/broadcastreceiver/receiver.cpp
@@ -48,8 +48,10 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <QtNetwork>
+#include <QLabel>
+#include <QPushButton>
+#include <QUdpSocket>
+#include <QVBoxLayout>
#include "receiver.h"
@@ -67,10 +69,11 @@ Receiver::Receiver(QWidget *parent)
//! [0]
//! [1]
- connect(udpSocket, SIGNAL(readyRead()),
- this, SLOT(processPendingDatagrams()));
+ connect(udpSocket, &QUdpSocket::readyRead,
+ this, &Receiver::processPendingDatagrams);
//! [1]
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(quitButton, &QPushButton::clicked,
+ this, &Receiver::close);
auto buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp
index a2d927d43d..61f8d35a3d 100644
--- a/examples/network/dnslookup/dnslookup.cpp
+++ b/examples/network/dnslookup/dnslookup.cpp
@@ -151,9 +151,9 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
//! [0]
DnsManager::DnsManager()
+ : dns(new QDnsLookup(this))
{
- dns = new QDnsLookup(this);
- connect(dns, SIGNAL(finished()), this, SLOT(showResults()));
+ connect(dns, &QDnsLookup::finished, this, &DnsManager::showResults);
}
void DnsManager::execute()
diff --git a/examples/network/doc/src/blockingfortuneclient.qdoc b/examples/network/doc/src/blockingfortuneclient.qdoc
index ecb9a7ba62..d1c0aa79bf 100644
--- a/examples/network/doc/src/blockingfortuneclient.qdoc
+++ b/examples/network/doc/src/blockingfortuneclient.qdoc
@@ -176,21 +176,20 @@
but its implementation is slightly different:
\snippet blockingfortuneclient/blockingclient.cpp 0
- \snippet blockingfortuneclient/blockingclient.cpp 1
We connect our FortuneThread's two signals newFortune() and error() (which
are somewhat similar to QTcpSocket::readyRead() and QTcpSocket::error() in
the previous example) to requestNewFortune() and displayError().
- \snippet blockingfortuneclient/blockingclient.cpp 2
+ \snippet blockingfortuneclient/blockingclient.cpp 1
The requestNewFortune() slot calls FortuneThread::requestNewFortune(),
which \e shedules the request. When the thread has received a new fortune
and emits newFortune(), our showFortune() slot is called:
- \snippet blockingfortuneclient/blockingclient.cpp 3
+ \snippet blockingfortuneclient/blockingclient.cpp 2
\codeline
- \snippet blockingfortuneclient/blockingclient.cpp 4
+ \snippet blockingfortuneclient/blockingclient.cpp 3
Here, we simply display the fortune we received as the argument.
diff --git a/examples/network/download/main.cpp b/examples/network/download/main.cpp
index 96111983ea..076dfdfd0b 100644
--- a/examples/network/download/main.cpp
+++ b/examples/network/download/main.cpp
@@ -80,8 +80,8 @@ public slots:
DownloadManager::DownloadManager()
{
- connect(&manager, SIGNAL(finished(QNetworkReply*)),
- SLOT(downloadFinished(QNetworkReply*)));
+ connect(&manager, &QNetworkAccessManager::finished,
+ this, &DownloadManager::downloadFinished);
}
void DownloadManager::doDownload(const QUrl &url)
@@ -90,8 +90,8 @@ void DownloadManager::doDownload(const QUrl &url)
QNetworkReply *reply = manager.get(request);
#if QT_CONFIG(ssl)
- connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
- SLOT(sslErrors(QList<QSslError>)));
+ connect(reply, &QNetworkReply::sslErrors,
+ this, &DownloadManager::sslErrors);
#endif
currentDownloads.append(reply);
diff --git a/examples/network/downloadmanager/downloadmanager.cpp b/examples/network/downloadmanager/downloadmanager.cpp
index 9e0c03c6af..cbad29541a 100644
--- a/examples/network/downloadmanager/downloadmanager.cpp
+++ b/examples/network/downloadmanager/downloadmanager.cpp
@@ -67,13 +67,13 @@ void DownloadManager::append(const QStringList &urls)
append(QUrl::fromEncoded(urlAsString.toLocal8Bit()));
if (downloadQueue.isEmpty())
- QTimer::singleShot(0, this, SIGNAL(finished()));
+ QTimer::singleShot(0, this, &DownloadManager::finished);
}
void DownloadManager::append(const QUrl &url)
{
if (downloadQueue.isEmpty())
- QTimer::singleShot(0, this, SLOT(startNextDownload()));
+ QTimer::singleShot(0, this, &DownloadManager::startNextDownload);
downloadQueue.enqueue(url);
++totalCount;
@@ -123,12 +123,12 @@ void DownloadManager::startNextDownload()
QNetworkRequest request(url);
currentDownload = manager.get(request);
- connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
- SLOT(downloadProgress(qint64,qint64)));
- connect(currentDownload, SIGNAL(finished()),
- SLOT(downloadFinished()));
- connect(currentDownload, SIGNAL(readyRead()),
- SLOT(downloadReadyRead()));
+ connect(currentDownload, &QNetworkReply::downloadProgress,
+ this, &DownloadManager::downloadProgress);
+ connect(currentDownload, &QNetworkReply::finished,
+ this, &DownloadManager::downloadFinished);
+ connect(currentDownload, &QNetworkReply::readyRead,
+ this, &DownloadManager::downloadReadyRead);
// prepare the output
printf("Downloading %s...\n", url.toEncoded().constData());
diff --git a/examples/network/downloadmanager/main.cpp b/examples/network/downloadmanager/main.cpp
index e3ba490992..eb1bd1ce9a 100644
--- a/examples/network/downloadmanager/main.cpp
+++ b/examples/network/downloadmanager/main.cpp
@@ -76,6 +76,7 @@ int main(int argc, char **argv)
DownloadManager manager;
manager.append(arguments);
- QObject::connect(&manager, SIGNAL(finished()), &app, SLOT(quit()));
+ QObject::connect(&manager, &DownloadManager::finished,
+ &app, &QCoreApplication::quit);
app.exec();
}
diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp
index d27beafd1e..2cba43178e 100644
--- a/examples/network/googlesuggest/googlesuggest.cpp
+++ b/examples/network/googlesuggest/googlesuggest.cpp
@@ -48,9 +48,9 @@
**
****************************************************************************/
-//! [1]
#include "googlesuggest.h"
+//! [1]
const QString gsuggestUrl(QStringLiteral("http://google.com/complete/search?output=toolbar&q=%1"));
//! [1]
@@ -74,16 +74,18 @@ GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), edit
popup->installEventFilter(this);
- connect(popup, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
- SLOT(doneCompletion()));
+ connect(popup, &QTreeWidget::itemClicked,
+ this, &GSuggestCompletion::doneCompletion);
timer.setSingleShot(true);
timer.setInterval(500);
- connect(&timer, SIGNAL(timeout()), SLOT(autoSuggest()));
- connect(editor, SIGNAL(textEdited(QString)), &timer, SLOT(start()));
+ connect(&timer, &QTimer::timeout,
+ this, &GSuggestCompletion::autoSuggest);
+ connect(editor, &QLineEdit::textEdited,
+ &timer, QOverload<>::of(&QTimer::start));
- connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
+ connect(&networkManager, &QNetworkAccessManager::finished,
+ this, &GSuggestCompletion::handleNetworkData);
}
//! [2]
diff --git a/examples/network/googlesuggest/searchbox.cpp b/examples/network/googlesuggest/searchbox.cpp
index d0bdb70daa..9057c1ccdf 100644
--- a/examples/network/googlesuggest/searchbox.cpp
+++ b/examples/network/googlesuggest/searchbox.cpp
@@ -57,11 +57,11 @@
const QString gsearchUrl = QStringLiteral("http://www.google.com/search?q=%1");
//! [1]
-SearchBox::SearchBox(QWidget *parent): QLineEdit(parent)
+SearchBox::SearchBox(QWidget *parent)
+ : QLineEdit(parent)
+ , completer(new GSuggestCompletion(this))
{
- completer = new GSuggestCompletion(this);
-
- connect(this, SIGNAL(returnPressed()),this, SLOT(doSearch()));
+ connect(this, &SearchBox::returnPressed, this, &SearchBox::doSearch);
setWindowTitle("Search with Google");
diff --git a/examples/network/multicastreceiver/receiver.cpp b/examples/network/multicastreceiver/receiver.cpp
index d793242ad0..3737d64f96 100644
--- a/examples/network/multicastreceiver/receiver.cpp
+++ b/examples/network/multicastreceiver/receiver.cpp
@@ -80,10 +80,12 @@ Receiver::Receiver(QWidget *parent)
!udpSocket6.joinMulticastGroup(groupAddress6))
statusLabel->setText(tr("Listening for multicast messages on IPv4 only"));
- connect(&udpSocket4, SIGNAL(readyRead()),
- this, SLOT(processPendingDatagrams()));
- connect(&udpSocket6, &QUdpSocket::readyRead, this, &Receiver::processPendingDatagrams);
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(&udpSocket4, &QUdpSocket::readyRead,
+ this, &Receiver::processPendingDatagrams);
+ connect(&udpSocket6, &QUdpSocket::readyRead,
+ this, &Receiver::processPendingDatagrams);
+ connect(quitButton, &QPushButton::clicked,
+ this, &Receiver::close);
}
void Receiver::processPendingDatagrams()
diff --git a/examples/network/multistreamclient/client.cpp b/examples/network/multistreamclient/client.cpp
index 112fb2e1a0..db6e3ba304 100644
--- a/examples/network/multistreamclient/client.cpp
+++ b/examples/network/multistreamclient/client.cpp
@@ -126,8 +126,8 @@ Client::Client(QWidget *parent)
connect(sctpSocket, &QSctpSocket::connected, this, &Client::connected);
connect(sctpSocket, &QSctpSocket::disconnected, this, &Client::disconnected);
connect(sctpSocket, &QSctpSocket::channelReadyRead, this, &Client::readDatagram);
- connect(sctpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(displayError(QAbstractSocket::SocketError)));
+ connect(sctpSocket, QOverload<QAbstractSocket::SocketError>::of(&QSctpSocket::error),
+ this, &Client::displayError);
connect(consumers[SctpChannels::Time], &Consumer::writeDatagram, this, &Client::writeDatagram);
connect(consumers[SctpChannels::Chat], &Consumer::writeDatagram, this, &Client::writeDatagram);
diff --git a/examples/network/network-chat/chatdialog.cpp b/examples/network/network-chat/chatdialog.cpp
index 615df3a318..ce6e39a8fc 100644
--- a/examples/network/network-chat/chatdialog.cpp
+++ b/examples/network/network-chat/chatdialog.cpp
@@ -62,14 +62,14 @@ ChatDialog::ChatDialog(QWidget *parent)
textEdit->setReadOnly(true);
listWidget->setFocusPolicy(Qt::NoFocus);
- connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- connect(&client, SIGNAL(newMessage(QString,QString)),
- this, SLOT(appendMessage(QString,QString)));
- connect(&client, SIGNAL(newParticipant(QString)),
- this, SLOT(newParticipant(QString)));
- connect(&client, SIGNAL(participantLeft(QString)),
- this, SLOT(participantLeft(QString)));
+ connect(lineEdit, &QLineEdit::returnPressed,
+ this, &ChatDialog::returnPressed);
+ connect(&client, &Client::newMessage,
+ this, &ChatDialog::appendMessage);
+ connect(&client, &Client::newParticipant,
+ this, &ChatDialog::newParticipant);
+ connect(&client, &Client::participantLeft,
+ this, &ChatDialog::participantLeft);
myNickName = client.nickName();
newParticipant(myNickName);
diff --git a/examples/network/network-chat/chatdialog.h b/examples/network/network-chat/chatdialog.h
index c65861c6e6..27ae0ca72a 100644
--- a/examples/network/network-chat/chatdialog.h
+++ b/examples/network/network-chat/chatdialog.h
@@ -59,7 +59,7 @@ class ChatDialog : public QDialog, private Ui::ChatDialog
Q_OBJECT
public:
- ChatDialog(QWidget *parent = 0);
+ ChatDialog(QWidget *parent = nullptr);
public slots:
void appendMessage(const QString &from, const QString &message);
diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp
index b76ef18238..d451181813 100644
--- a/examples/network/network-chat/client.cpp
+++ b/examples/network/network-chat/client.cpp
@@ -60,10 +60,10 @@ Client::Client()
peerManager->setServerPort(server.serverPort());
peerManager->startBroadcasting();
- QObject::connect(peerManager, SIGNAL(newConnection(Connection*)),
- this, SLOT(newConnection(Connection*)));
- QObject::connect(&server, SIGNAL(newConnection(Connection*)),
- this, SLOT(newConnection(Connection*)));
+ connect(peerManager, &PeerManager::newConnection,
+ this, &Client::newConnection);
+ connect(&server, &Server::newConnection,
+ this, &Client::newConnection);
}
void Client::sendMessage(const QString &message)
@@ -102,10 +102,10 @@ void Client::newConnection(Connection *connection)
{
connection->setGreetingMessage(peerManager->userName());
- connect(connection, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(connectionError(QAbstractSocket::SocketError)));
- connect(connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
- connect(connection, SIGNAL(readyForUse()), this, SLOT(readyForUse()));
+ connect(connection, QOverload<QAbstractSocket::SocketError>::of(&Connection::error),
+ this, &Client::connectionError);
+ connect(connection, &Connection::disconnected, this, &Client::disconnected);
+ connect(connection, &Connection::readyForUse, this, &Client::readyForUse);
}
void Client::readyForUse()
@@ -115,8 +115,8 @@ void Client::readyForUse()
connection->peerPort()))
return;
- connect(connection, SIGNAL(newMessage(QString,QString)),
- this, SIGNAL(newMessage(QString,QString)));
+ connect(connection, &Connection::newMessage,
+ this, &Client::newMessage);
peers.insert(connection->peerAddress(), connection);
QString nick = connection->name();
diff --git a/examples/network/network-chat/connection.cpp b/examples/network/network-chat/connection.cpp
index 58cf67eb6d..cffd495349 100644
--- a/examples/network/network-chat/connection.cpp
+++ b/examples/network/network-chat/connection.cpp
@@ -82,11 +82,14 @@ Connection::Connection(QObject *parent)
isGreetingMessageSent = false;
pingTimer.setInterval(PingInterval);
- QObject::connect(this, SIGNAL(readyRead()), this, SLOT(processReadyRead()));
- QObject::connect(this, SIGNAL(disconnected()), &pingTimer, SLOT(stop()));
- QObject::connect(&pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
- QObject::connect(this, SIGNAL(connected()),
- this, SLOT(sendGreetingMessage()));
+ connect(this, &QTcpSocket::readyRead, this,
+ &Connection::processReadyRead);
+ connect(this, &QTcpSocket::disconnected,
+ &pingTimer, &QTimer::stop);
+ connect(&pingTimer, &QTimer::timeout,
+ this, &Connection::sendPing);
+ connect(this, &QTcpSocket::connected,
+ this, &Connection::sendGreetingMessage);
}
Connection::Connection(qintptr socketDescriptor, QObject *parent)
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
index fa0671a522..e6f36f7cd9 100644
--- a/examples/network/network-chat/connection.h
+++ b/examples/network/network-chat/connection.h
@@ -79,8 +79,8 @@ public:
Undefined
};
- Connection(QObject *parent = 0);
- Connection(qintptr socketDescriptor, QObject *parent = 0);
+ Connection(QObject *parent = nullptr);
+ Connection(qintptr socketDescriptor, QObject *parent = nullptr);
~Connection();
QString name() const;
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
index 5c48edb1b9..2c9d182211 100644
--- a/examples/network/network-chat/peermanager.cpp
+++ b/examples/network/network-chat/peermanager.cpp
@@ -81,12 +81,12 @@ PeerManager::PeerManager(Client *client)
broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
| QUdpSocket::ReuseAddressHint);
- connect(&broadcastSocket, SIGNAL(readyRead()),
- this, SLOT(readBroadcastDatagram()));
+ connect(&broadcastSocket, &QUdpSocket::readyRead,
+ this, &PeerManager::readBroadcastDatagram);
broadcastTimer.setInterval(BroadcastInterval);
- connect(&broadcastTimer, SIGNAL(timeout()),
- this, SLOT(sendBroadcastDatagram()));
+ connect(&broadcastTimer, &QTimer::timeout,
+ this, &PeerManager::sendBroadcastDatagram);
}
void PeerManager::setServerPort(int port)
diff --git a/examples/network/network-chat/server.h b/examples/network/network-chat/server.h
index d86ed36bce..0a7e6e18c1 100644
--- a/examples/network/network-chat/server.h
+++ b/examples/network/network-chat/server.h
@@ -60,7 +60,7 @@ class Server : public QTcpServer
Q_OBJECT
public:
- Server(QObject *parent = 0);
+ Server(QObject *parent = nullptr);
signals:
void newConnection(Connection *connection);
diff --git a/examples/network/securesocketclient/main.cpp b/examples/network/securesocketclient/main.cpp
index e9c413577f..7cda94cc34 100644
--- a/examples/network/securesocketclient/main.cpp
+++ b/examples/network/securesocketclient/main.cpp
@@ -63,8 +63,8 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
if (!QSslSocket::supportsSsl()) {
- QMessageBox::information(0, "Secure Socket Client",
- "This system does not support SSL/TLS.");
+ QMessageBox::information(nullptr, "Secure Socket Client",
+ "This system does not support TLS.");
return -1;
}
diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp
index 79ed7746d6..6eb1075996 100644
--- a/examples/network/securesocketclient/sslclient.cpp
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -54,8 +54,6 @@
#include "ui_sslclient.h"
#include "ui_sslerrors.h"
-#include <QtCore>
-
SslClient::SslClient(QWidget *parent)
: QWidget(parent)
{
@@ -185,16 +183,17 @@ void SslClient::setupUi()
form->hostNameEdit->setSelection(0, form->hostNameEdit->text().size());
form->sessionOutput->setHtml(tr("&lt;not connected&gt;"));
- connect(form->hostNameEdit, SIGNAL(textChanged(QString)),
- this, SLOT(updateEnabledState()));
- connect(form->connectButton, SIGNAL(clicked()),
- this, SLOT(secureConnect()));
- connect(form->sendButton, SIGNAL(clicked()),
- this, SLOT(sendData()));
+ connect(form->hostNameEdit, &QLineEdit::textChanged,
+ this, &SslClient::updateEnabledState);
+ connect(form->connectButton, &QPushButton::clicked,
+ this, &SslClient::secureConnect);
+ connect(form->sendButton, &QPushButton::clicked,
+ this, &SslClient::sendData);
padLock = new QToolButton;
padLock->setIcon(QIcon(":/encrypted.png"));
- connect(padLock, SIGNAL(clicked()), this, SLOT(displayCertificateInfo()));
+ connect(padLock, &QToolButton::clicked,
+ this, &SslClient::displayCertificateInfo);
#if QT_CONFIG(cursor)
padLock->setCursor(Qt::ArrowCursor);
@@ -223,16 +222,16 @@ void SslClient::setupSecureSocket()
socket = new QSslSocket(this);
- connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
- this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
- connect(socket, SIGNAL(encrypted()),
- this, SLOT(socketEncrypted()));
- connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(socketError(QAbstractSocket::SocketError)));
- connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
- this, SLOT(sslErrors(QList<QSslError>)));
- connect(socket, SIGNAL(readyRead()),
- this, SLOT(socketReadyRead()));
+ connect(socket, &QSslSocket::stateChanged,
+ this, &SslClient::socketStateChanged);
+ connect(socket, &QSslSocket::encrypted,
+ this, &SslClient::socketEncrypted);
+ connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error),
+ this, &SslClient::socketError);
+ connect(socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors),
+ this, &SslClient::sslErrors);
+ connect(socket, &QSslSocket::readyRead,
+ this, &SslClient::socketReadyRead);
}
diff --git a/examples/network/threadedfortuneserver/dialog.cpp b/examples/network/threadedfortuneserver/dialog.cpp
index fcd6655ab9..e5b389f1e6 100644
--- a/examples/network/threadedfortuneserver/dialog.cpp
+++ b/examples/network/threadedfortuneserver/dialog.cpp
@@ -89,7 +89,7 @@ Dialog::Dialog(QWidget *parent)
"Run the Fortune Client example now.")
.arg(ipAddress).arg(server.serverPort()));
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(quitButton, &QPushButton::clicked, this, &Dialog::close);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
diff --git a/examples/network/threadedfortuneserver/dialog.h b/examples/network/threadedfortuneserver/dialog.h
index d127b8bfc2..2898c5311c 100644
--- a/examples/network/threadedfortuneserver/dialog.h
+++ b/examples/network/threadedfortuneserver/dialog.h
@@ -64,7 +64,7 @@ class Dialog : public QWidget
Q_OBJECT
public:
- Dialog(QWidget *parent = 0);
+ Dialog(QWidget *parent = nullptr);
private:
QLabel *statusLabel;
diff --git a/examples/network/threadedfortuneserver/fortuneserver.cpp b/examples/network/threadedfortuneserver/fortuneserver.cpp
index 791ffc71f4..73d7e22531 100644
--- a/examples/network/threadedfortuneserver/fortuneserver.cpp
+++ b/examples/network/threadedfortuneserver/fortuneserver.cpp
@@ -74,7 +74,7 @@ void FortuneServer::incomingConnection(qintptr socketDescriptor)
{
QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size()));
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
- connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+ connect(thread, &FortuneThread::finished, thread, &FortuneThread::deleteLater);
thread->start();
}
//! [1]
diff --git a/examples/network/threadedfortuneserver/fortuneserver.h b/examples/network/threadedfortuneserver/fortuneserver.h
index dc0949bcb2..26ea3d1cbb 100644
--- a/examples/network/threadedfortuneserver/fortuneserver.h
+++ b/examples/network/threadedfortuneserver/fortuneserver.h
@@ -60,7 +60,7 @@ class FortuneServer : public QTcpServer
Q_OBJECT
public:
- FortuneServer(QObject *parent = 0);
+ FortuneServer(QObject *parent = nullptr);
protected:
void incomingConnection(qintptr socketDescriptor) override;
diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp
index c87110ac4a..129ad8c968 100644
--- a/examples/network/torrent/addtorrentdialog.cpp
+++ b/examples/network/torrent/addtorrentdialog.cpp
@@ -73,12 +73,12 @@ AddTorrentDialog::AddTorrentDialog(QWidget *parent)
{
ui.setupUi(this);
- connect(ui.browseTorrents, SIGNAL(clicked()),
- this, SLOT(selectTorrent()));
- connect(ui.browseDestination, SIGNAL(clicked()),
- this, SLOT(selectDestination()));
- connect(ui.torrentFile, SIGNAL(textChanged(QString)),
- this, SLOT(setTorrent(QString)));
+ connect(ui.browseTorrents, &QPushButton::clicked,
+ this, &AddTorrentDialog::selectTorrent);
+ connect(ui.browseDestination, &QPushButton::clicked,
+ this, &AddTorrentDialog::selectDestination);
+ connect(ui.torrentFile, &QLineEdit::textChanged,
+ this, &AddTorrentDialog::setTorrent);
ui.destinationFolder->setText(destinationDirectory = QDir::current().path());
ui.torrentFile->setFocus();
diff --git a/examples/network/torrent/addtorrentdialog.h b/examples/network/torrent/addtorrentdialog.h
index b5bd1df84f..00546c624c 100644
--- a/examples/network/torrent/addtorrentdialog.h
+++ b/examples/network/torrent/addtorrentdialog.h
@@ -60,7 +60,7 @@ class AddTorrentDialog : public QDialog
Q_OBJECT
public:
- AddTorrentDialog(QWidget *parent = 0);
+ AddTorrentDialog(QWidget *parent = nullptr);
QString torrentFileName() const;
QString destinationFolder() const;
diff --git a/examples/network/torrent/filemanager.h b/examples/network/torrent/filemanager.h
index 82f9983ea6..1438ed5404 100644
--- a/examples/network/torrent/filemanager.h
+++ b/examples/network/torrent/filemanager.h
@@ -70,7 +70,7 @@ class FileManager : public QThread
Q_OBJECT
public:
- FileManager(QObject *parent = 0);
+ FileManager(QObject *parent = nullptr);
virtual ~FileManager();
inline void setMetaInfo(const MetaInfo &info) { metaInfo = info; }
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 704012ef6d..331fa12944 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -60,7 +60,7 @@ class TorrentView : public QTreeWidget
{
Q_OBJECT
public:
- TorrentView(QWidget *parent = 0);
+ TorrentView(QWidget *parent = nullptr);
#if QT_CONFIG(draganddrop)
signals:
@@ -110,7 +110,7 @@ public:
};
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), quitDialog(0), saveChanges(false)
+ : QMainWindow(parent), quitDialog(nullptr), saveChanges(false)
{
// Initialize some static strings
QStringList headers;
@@ -147,12 +147,12 @@ MainWindow::MainWindow(QWidget *parent)
fileMenu->addAction(pauseTorrentAction);
fileMenu->addAction(removeTorrentAction);
fileMenu->addSeparator();
- fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, SLOT(close()));
+ fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, &MainWindow::close);
// Help menu
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
- helpMenu->addAction(tr("&About"), this, SLOT(about()));
- helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+ helpMenu->addAction(tr("&About"), this, &MainWindow::about);
+ helpMenu->addAction(tr("About &Qt"), qApp, QApplication::aboutQt);
// Top toolbar
QToolBar *topBar = new QToolBar(tr("Tools"));
@@ -188,24 +188,24 @@ MainWindow::MainWindow(QWidget *parent)
#endif
// Set up connections
- connect(torrentView, SIGNAL(itemSelectionChanged()),
- this, SLOT(setActionsEnabled()));
- connect(torrentView, SIGNAL(fileDropped(QString)),
- this, SLOT(acceptFileDrop(QString)));
- connect(uploadLimitSlider, SIGNAL(valueChanged(int)),
- this, SLOT(setUploadLimit(int)));
- connect(downloadLimitSlider, SIGNAL(valueChanged(int)),
- this, SLOT(setDownloadLimit(int)));
- connect(newTorrentAction, SIGNAL(triggered()),
- this, SLOT(addTorrent()));
- connect(pauseTorrentAction, SIGNAL(triggered()),
- this, SLOT(pauseTorrent()));
- connect(removeTorrentAction, SIGNAL(triggered()),
- this, SLOT(removeTorrent()));
- connect(upActionTool, SIGNAL(triggered(bool)),
- this, SLOT(moveTorrentUp()));
- connect(downActionTool, SIGNAL(triggered(bool)),
- this, SLOT(moveTorrentDown()));
+ connect(torrentView, &TorrentView::itemSelectionChanged,
+ this, &MainWindow::setActionsEnabled);
+ connect(torrentView, &TorrentView::fileDropped,
+ this, &MainWindow::acceptFileDrop);
+ connect(uploadLimitSlider, &QSlider::valueChanged,
+ this, &MainWindow::setUploadLimit);
+ connect(downloadLimitSlider, &QSlider::valueChanged,
+ this, &MainWindow::setDownloadLimit);
+ connect(newTorrentAction, &QAction::triggered,
+ this, QOverload<>::of(&MainWindow::addTorrent));
+ connect(pauseTorrentAction, &QAction::triggered,
+ this, &MainWindow::pauseTorrent);
+ connect(removeTorrentAction, &QAction::triggered,
+ this, &MainWindow::removeTorrent);
+ connect(upActionTool, &QAction::triggered,
+ this, &MainWindow::moveTorrentUp);
+ connect(downActionTool, &QAction::triggered,
+ this, &MainWindow::moveTorrentDown);
// Load settings and start
setWindowTitle(tr("Torrent Client"));
@@ -297,7 +297,7 @@ bool MainWindow::addTorrent()
addTorrent(fileName, addTorrentDialog->destinationFolder());
if (!saveChanges) {
saveChanges = true;
- QTimer::singleShot(1000, this, SLOT(saveSettings()));
+ QTimer::singleShot(1000, this, &MainWindow::saveSettings);
}
return true;
}
@@ -311,7 +311,8 @@ void MainWindow::removeTorrent()
// Stop the client.
client->disconnect();
- connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
+ connect(client, &TorrentClient::stopped,
+ this, &MainWindow::torrentStopped);
client->stop();
// Remove the row from the view.
@@ -379,13 +380,20 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
client->setDumpedState(resumeState);
// Setup the client connections.
- connect(client, SIGNAL(stateChanged(TorrentClient::State)), this, SLOT(updateState(TorrentClient::State)));
- connect(client, SIGNAL(peerInfoUpdated()), this, SLOT(updatePeerInfo()));
- connect(client, SIGNAL(progressUpdated(int)), this, SLOT(updateProgress(int)));
- connect(client, SIGNAL(downloadRateUpdated(int)), this, SLOT(updateDownloadRate(int)));
- connect(client, SIGNAL(uploadRateUpdated(int)), this, SLOT(updateUploadRate(int)));
- connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
- connect(client, SIGNAL(error(TorrentClient::Error)), this, SLOT(torrentError(TorrentClient::Error)));
+ connect(client, &TorrentClient::stateChanged,
+ this, &MainWindow::updateState);
+ connect(client, &TorrentClient::peerInfoUpdated,
+ this, &MainWindow::updatePeerInfo);
+ connect(client, &TorrentClient::progressUpdated,
+ this, &MainWindow::updateProgress);
+ connect(client, &TorrentClient::downloadRateUpdated,
+ this, &MainWindow::updateDownloadRate);
+ connect(client, &TorrentClient::uploadRateUpdated,
+ this, &MainWindow::updateUploadRate);
+ connect(client, &TorrentClient::stopped,
+ this, &MainWindow::torrentStopped);
+ connect(client, QOverload<TorrentClient::Error>::of(&TorrentClient::error),
+ this, &MainWindow::torrentError);
// Add the client to the list of downloading jobs.
Job job;
@@ -414,7 +422,7 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
if (!saveChanges) {
saveChanges = true;
- QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ QTimer::singleShot(5000, this, &MainWindow::saveSettings);
}
client->start();
return true;
@@ -491,15 +499,15 @@ void MainWindow::setActionsEnabled()
{
// Find the view item and client for the current row, and update
// the states of the actions.
- QTreeWidgetItem *item = 0;
+ QTreeWidgetItem *item = nullptr;
if (!torrentView->selectedItems().isEmpty())
item = torrentView->selectedItems().first();
- TorrentClient *client = item ? jobs.at(torrentView->indexOfTopLevelItem(item)).client : 0;
+ TorrentClient *client = item ? jobs.at(torrentView->indexOfTopLevelItem(item)).client : nullptr;
bool pauseEnabled = client && ((client->state() == TorrentClient::Paused)
|| (client->state() > TorrentClient::Preparing));
- removeTorrentAction->setEnabled(item != 0);
- pauseTorrentAction->setEnabled(item != 0 && pauseEnabled);
+ removeTorrentAction->setEnabled(item != nullptr);
+ pauseTorrentAction->setEnabled(item && pauseEnabled);
if (client && client->state() == TorrentClient::Paused) {
pauseTorrentAction->setIcon(QIcon(":/icons/player_play.png"));
@@ -524,7 +532,7 @@ void MainWindow::updateDownloadRate(int bytesPerSecond)
if (!saveChanges) {
saveChanges = true;
- QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ QTimer::singleShot(5000, this, &MainWindow::saveSettings);
}
}
@@ -538,7 +546,7 @@ void MainWindow::updateUploadRate(int bytesPerSecond)
if (!saveChanges) {
saveChanges = true;
- QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ QTimer::singleShot(5000, this, &MainWindow::saveSettings);
}
}
@@ -649,7 +657,7 @@ void MainWindow::about()
about.setWindowTitle(tr("About Torrent Client"));
about.setLayout(mainLayout);
- connect(quitButton, SIGNAL(clicked()), &about, SLOT(close()));
+ connect(quitButton, &QPushButton::clicked, &about, &QDialog::close);
about.exec();
}
@@ -688,7 +696,7 @@ void MainWindow::closeEvent(QCloseEvent *)
++jobsToStop;
TorrentClient *client = job.client;
client->disconnect();
- connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
+ connect(client, &TorrentClient::stopped, this, &MainWindow::torrentStopped);
client->stop();
delete torrentView->takeTopLevelItem(0);
}
@@ -696,7 +704,7 @@ void MainWindow::closeEvent(QCloseEvent *)
if (jobsToStop > jobsStopped)
quitDialog->exec();
quitDialog->deleteLater();
- quitDialog = 0;
+ quitDialog = nullptr;
}
TorrentView::TorrentView(QWidget *parent)
diff --git a/examples/network/torrent/mainwindow.h b/examples/network/torrent/mainwindow.h
index 9c55b72256..78542b535b 100644
--- a/examples/network/torrent/mainwindow.h
+++ b/examples/network/torrent/mainwindow.h
@@ -71,7 +71,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
QSize sizeHint() const override;
const TorrentClient *clientForRow(int row) const;
diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp
index 7a53c85f0c..cea4ef53fa 100644
--- a/examples/network/torrent/peerwireclient.cpp
+++ b/examples/network/torrent/peerwireclient.cpp
@@ -87,7 +87,7 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
: QTcpSocket(parent), pendingBlockSizes(0),
pwState(ChokingPeer | ChokedByPeer), receivedHandShake(false), gotPeerId(false),
sentHandShake(false), nextPacketLength(-1), pendingRequestTimer(0), invalidateTimeout(false),
- keepAliveTimer(0), torrentPeer(0)
+ keepAliveTimer(0), torrentPeer(nullptr)
{
memset(uploadSpeedData, 0, sizeof(uploadSpeedData));
memset(downloadSpeedData, 0, sizeof(downloadSpeedData));
@@ -96,21 +96,23 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
timeoutTimer = startTimer(ConnectTimeout);
peerIdString = peerId;
- connect(this, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer()));
- connect(this, SIGNAL(connected()), this, SIGNAL(readyToTransfer()));
-
- connect(&socket, SIGNAL(connected()),
- this, SIGNAL(connected()));
- connect(&socket, SIGNAL(readyRead()),
- this, SIGNAL(readyRead()));
- connect(&socket, SIGNAL(disconnected()),
- this, SIGNAL(disconnected()));
- connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SIGNAL(error(QAbstractSocket::SocketError)));
- connect(&socket, SIGNAL(bytesWritten(qint64)),
- this, SIGNAL(bytesWritten(qint64)));
- connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
- this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+ connect(this, &PeerWireClient::readyRead,
+ this, &PeerWireClient::readyToTransfer);
+ connect(this, &PeerWireClient::connected,
+ this, &PeerWireClient::readyToTransfer);
+
+ connect(&socket, &QTcpSocket::connected,
+ this, &PeerWireClient::connected);
+ connect(&socket, &QTcpSocket::readyRead,
+ this, &PeerWireClient::readyRead);
+ connect(&socket, &QTcpSocket::disconnected,
+ this, &PeerWireClient::disconnected);
+ connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error),
+ this, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error));
+ connect(&socket, &QTcpSocket::bytesWritten,
+ this, &PeerWireClient::bytesWritten);
+ connect(&socket, &QTcpSocket::stateChanged,
+ this, &PeerWireClient::socketStateChanged);
}
diff --git a/examples/network/torrent/peerwireclient.h b/examples/network/torrent/peerwireclient.h
index e03b538f63..75edf8ee77 100644
--- a/examples/network/torrent/peerwireclient.h
+++ b/examples/network/torrent/peerwireclient.h
@@ -92,7 +92,7 @@ public:
};
Q_DECLARE_FLAGS(PeerWireState, PeerWireStateFlag)
- explicit PeerWireClient(const QByteArray &peerId, QObject *parent = 0);
+ explicit PeerWireClient(const QByteArray &peerId, QObject *parent = nullptr);
void initialize(const QByteArray &infoHash, int pieceCount);
void setPeer(TorrentPeer *peer);
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
index 96474806f5..756947b65c 100644
--- a/examples/network/torrent/ratecontroller.cpp
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -62,7 +62,8 @@ RateController *RateController::instance()
void RateController::addSocket(PeerWireClient *socket)
{
- connect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
+ connect(socket, &PeerWireClient::readyToTransfer,
+ this, &RateController::scheduleTransfer);
socket->setReadBufferSize(downLimit * 4);
sockets << socket;
scheduleTransfer();
@@ -70,7 +71,8 @@ void RateController::addSocket(PeerWireClient *socket)
void RateController::removeSocket(PeerWireClient *socket)
{
- disconnect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
+ disconnect(socket, &PeerWireClient::readyToTransfer,
+ this, &RateController::scheduleTransfer);
socket->setReadBufferSize(0);
sockets.remove(socket);
}
diff --git a/examples/network/torrent/ratecontroller.h b/examples/network/torrent/ratecontroller.h
index f8bff0cc36..593a76f592 100644
--- a/examples/network/torrent/ratecontroller.h
+++ b/examples/network/torrent/ratecontroller.h
@@ -62,8 +62,7 @@ class RateController : public QObject
Q_OBJECT
public:
- inline RateController(QObject *parent = 0)
- : QObject(parent), transferScheduled(false) { }
+ using QObject::QObject;
static RateController *instance();
void addSocket(PeerWireClient *socket);
@@ -81,9 +80,9 @@ public slots:
private:
QElapsedTimer stopWatch;
QSet<PeerWireClient *> sockets;
- int upLimit;
- int downLimit;
- bool transferScheduled;
+ int upLimit = 0;
+ int downLimit = 0;
+ bool transferScheduled = false;
};
#endif
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index bddf3caa1a..6b11338f42 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -75,13 +75,12 @@ static const int MinimumTimeBeforeRevisit = 30;
static const int MaxUploads = 4;
static const int UploadScheduleInterval = 10000;
-class TorrentPiece {
-public:
- int index;
- int length;
+struct TorrentPiece {
QBitArray completedBlocks;
QBitArray requestedBlocks;
- bool inProgress;
+ int index = 0;
+ int length = 0;
+ bool inProgress = false;
};
class TorrentClientPrivate
@@ -227,7 +226,7 @@ void TorrentClientPrivate::callPeerConnector()
{
if (!connectingToClients) {
connectingToClients = true;
- QTimer::singleShot(10000, q, SLOT(connectToPeers()));
+ QTimer::singleShot(10000, q, &TorrentClient::connectToPeers);
}
}
@@ -235,22 +234,22 @@ TorrentClient::TorrentClient(QObject *parent)
: QObject(parent), d(new TorrentClientPrivate(this))
{
// Connect the file manager
- connect(&d->fileManager, SIGNAL(dataRead(int,int,int,QByteArray)),
- this, SLOT(sendToPeer(int,int,int,QByteArray)));
- connect(&d->fileManager, SIGNAL(verificationProgress(int)),
- this, SLOT(updateProgress(int)));
- connect(&d->fileManager, SIGNAL(verificationDone()),
- this, SLOT(fullVerificationDone()));
- connect(&d->fileManager, SIGNAL(pieceVerified(int,bool)),
- this, SLOT(pieceVerified(int,bool)));
- connect(&d->fileManager, SIGNAL(error()),
- this, SLOT(handleFileError()));
+ connect(&d->fileManager, &FileManager::dataRead,
+ this, &TorrentClient::sendToPeer);
+ connect(&d->fileManager, &FileManager::verificationProgress,
+ this, &TorrentClient::updateProgress);
+ connect(&d->fileManager, &FileManager::verificationDone,
+ this, &TorrentClient::fullVerificationDone);
+ connect(&d->fileManager, &FileManager::pieceVerified,
+ this, &TorrentClient::pieceVerified);
+ connect(&d->fileManager, &FileManager::error,
+ this, &TorrentClient::handleFileError);
// Connect the tracker client
- connect(&d->trackerClient, SIGNAL(peerListUpdated(QList<TorrentPeer>)),
- this, SLOT(addToPeerList(QList<TorrentPeer>)));
- connect(&d->trackerClient, SIGNAL(stopped()),
- this, SIGNAL(stopped()));
+ connect(&d->trackerClient, &TrackerClient::peerListUpdated,
+ this, &TorrentClient::addToPeerList);
+ connect(&d->trackerClient, &TrackerClient::stopped,
+ this, &TorrentClient::stopped);
}
TorrentClient::~TorrentClient()
@@ -840,26 +839,26 @@ void TorrentClient::setupOutgoingConnection()
void TorrentClient::initializeConnection(PeerWireClient *client)
{
- connect(client, SIGNAL(connected()),
- this, SLOT(setupOutgoingConnection()));
- connect(client, SIGNAL(disconnected()),
- this, SLOT(removeClient()));
- connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(removeClient()));
- connect(client, SIGNAL(piecesAvailable(QBitArray)),
- this, SLOT(peerPiecesAvailable(QBitArray)));
- connect(client, SIGNAL(blockRequested(int,int,int)),
- this, SLOT(peerRequestsBlock(int,int,int)));
- connect(client, SIGNAL(blockReceived(int,int,QByteArray)),
- this, SLOT(blockReceived(int,int,QByteArray)));
- connect(client, SIGNAL(choked()),
- this, SLOT(peerChoked()));
- connect(client, SIGNAL(unchoked()),
- this, SLOT(peerUnchoked()));
- connect(client, SIGNAL(bytesWritten(qint64)),
- this, SLOT(peerWireBytesWritten(qint64)));
- connect(client, SIGNAL(bytesReceived(qint64)),
- this, SLOT(peerWireBytesReceived(qint64)));
+ connect(client, &PeerWireClient::connected,
+ this, &TorrentClient::setupOutgoingConnection);
+ connect(client, &PeerWireClient::disconnected,
+ this, &TorrentClient::removeClient);
+ connect(client, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error),
+ this, &TorrentClient::removeClient);
+ connect(client, &PeerWireClient::piecesAvailable,
+ this, &TorrentClient::peerPiecesAvailable);
+ connect(client, &PeerWireClient::blockRequested,
+ this, &TorrentClient::peerRequestsBlock);
+ connect(client, &PeerWireClient::blockReceived,
+ this, &TorrentClient::blockReceived);
+ connect(client, &PeerWireClient::choked,
+ this, &TorrentClient::peerChoked);
+ connect(client, &PeerWireClient::unchoked,
+ this, &TorrentClient::peerUnchoked);
+ connect(client, &PeerWireClient::bytesWritten,
+ this, &TorrentClient::peerWireBytesWritten);
+ connect(client, &PeerWireClient::bytesReceived,
+ this, &TorrentClient::peerWireBytesReceived);
}
void TorrentClient::removeClient()
@@ -890,7 +889,8 @@ void TorrentClient::removeClient()
}
// Delete the client later.
- disconnect(client, SIGNAL(disconnected()), this, SLOT(removeClient()));
+ disconnect(client, &PeerWireClient::disconnected,
+ this, &TorrentClient::removeClient);
client->deleteLater();
ConnectionManager::instance()->removeConnection(client);
@@ -905,7 +905,7 @@ void TorrentClient::peerPiecesAvailable(const QBitArray &pieces)
// Find the peer in our list of announced peers. If it's there,
// then we can use the piece list into to gather statistics that
// help us decide what peers to connect to.
- TorrentPeer *peer = 0;
+ TorrentPeer *peer = nullptr;
QList<TorrentPeer *>::Iterator it = d->peers.begin();
while (it != d->peers.end()) {
if ((*it)->address == client->peerAddress() && (*it)->port == client->peerPort()) {
@@ -1163,7 +1163,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
// many blocks have been requested.
QList<int> currentPieces;
bool somePiecesAreNotInProgress = false;
- TorrentPiece *lastPendingPiece = 0;
+ TorrentPiece *lastPendingPiece = nullptr;
QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
while (it != d->payloads.end() && it.key() == client) {
lastPendingPiece = it.value();
@@ -1183,7 +1183,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
// If all pieces are in progress, but we haven't filled up our
// block requesting quota, then we need to schedule another piece.
if (!somePiecesAreNotInProgress || client->incomingBlocks().size() > 0)
- lastPendingPiece = 0;
+ lastPendingPiece = nullptr;
TorrentPiece *piece = lastPendingPiece;
// In warmup state, all clients request blocks from the same pieces.
diff --git a/examples/network/torrent/torrentclient.h b/examples/network/torrent/torrentclient.h
index b9b88b3a07..ad77caa66c 100644
--- a/examples/network/torrent/torrentclient.h
+++ b/examples/network/torrent/torrentclient.h
@@ -58,8 +58,7 @@
class MetaInfo;
class PeerWireClient;
class TorrentClientPrivate;
-class TorrentPeer;
-class TorrentPiece;
+struct TorrentPiece;
QT_BEGIN_NAMESPACE
class QTimerEvent;
QT_END_NAMESPACE
@@ -110,7 +109,7 @@ public:
ServerError
};
- TorrentClient(QObject *parent = 0);
+ TorrentClient(QObject *parent = nullptr);
~TorrentClient();
bool setTorrent(const QString &fileName);
diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp
index c68f33249c..215498194b 100644
--- a/examples/network/torrent/torrentserver.cpp
+++ b/examples/network/torrent/torrentserver.cpp
@@ -78,10 +78,10 @@ void TorrentServer::incomingConnection(qintptr socketDescriptor)
if (client->setSocketDescriptor(socketDescriptor)) {
if (ConnectionManager::instance()->canAddConnection() && !clients.isEmpty()) {
- connect(client, SIGNAL(infoHashReceived(QByteArray)),
- this, SLOT(processInfoHash(QByteArray)));
- connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(removeClient()));
+ connect(client, &PeerWireClient::infoHashReceived,
+ this, &TorrentServer::processInfoHash);
+ connect(client, QOverload<QAbstractSocket::SocketError>::of(&PeerWireClient::error),
+ this, QOverload<>::of(&TorrentServer::removeClient));
RateController::instance()->addSocket(client);
ConnectionManager::instance()->addConnection(client);
return;
@@ -104,7 +104,7 @@ void TorrentServer::processInfoHash(const QByteArray &infoHash)
PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
for (TorrentClient *client : qAsConst(clients)) {
if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
- peer->disconnect(peer, 0, this, 0);
+ peer->disconnect(peer, nullptr, this, nullptr);
client->setupIncomingConnection(peer);
return;
}
diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp
index e883317b12..00810a98af 100644
--- a/examples/network/torrent/trackerclient.cpp
+++ b/examples/network/torrent/trackerclient.cpp
@@ -60,14 +60,8 @@
TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
: QObject(parent), torrentDownloader(downloader)
{
- length = 0;
- requestInterval = 5 * 60;
- requestIntervalTimer = -1;
- firstTrackerRequest = true;
- lastTrackerRequest = false;
- firstSeeding = true;
-
- connect(&http, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpRequestDone(QNetworkReply*)));
+ connect(&http, &QNetworkAccessManager::finished,
+ this, &TrackerClient::httpRequestDone);
}
void TrackerClient::start(const MetaInfo &info)
@@ -157,8 +151,8 @@ void TrackerClient::fetchPeerList()
if (!url.userName().isEmpty()) {
uname = url.userName();
pwd = url.password();
- connect(&http, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
- this, SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
+ connect(&http, &QNetworkAccessManager::authenticationRequired,
+ this, &TrackerClient::provideAuthentication);
}
http.get(req);
}
diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h
index 323fc67eba..b8c169ff22 100644
--- a/examples/network/torrent/trackerclient.h
+++ b/examples/network/torrent/trackerclient.h
@@ -69,7 +69,7 @@ class TrackerClient : public QObject
Q_OBJECT
public:
- explicit TrackerClient(TorrentClient *downloader, QObject *parent = 0);
+ explicit TrackerClient(TorrentClient *downloader, QObject *parent = nullptr);
void start(const MetaInfo &info);
void stop();
@@ -98,21 +98,19 @@ private slots:
private:
TorrentClient *torrentDownloader;
- int requestInterval;
- int requestIntervalTimer;
+ int requestInterval = 5 * 60;
+ int requestIntervalTimer = -1;
QNetworkAccessManager http;
MetaInfo metaInfo;
QByteArray trackerId;
QList<TorrentPeer> peers;
- qint64 uploadedBytes;
- qint64 downloadedBytes;
- qint64 length;
+ qint64 length = 0;
QString uname;
QString pwd;
- bool firstTrackerRequest;
- bool lastTrackerRequest;
- bool firstSeeding;
+ bool firstTrackerRequest = true;
+ bool lastTrackerRequest = false;
+ bool firstSeeding = true;
};
#endif
diff --git a/examples/opengl/computegles31/glwindow.cpp b/examples/opengl/computegles31/glwindow.cpp
index 29ec9fcff7..5e8d45da24 100644
--- a/examples/opengl/computegles31/glwindow.cpp
+++ b/examples/opengl/computegles31/glwindow.cpp
@@ -73,15 +73,6 @@
#endif
GLWindow::GLWindow()
- : m_texImageInput(0),
- m_texImageTmp(0),
- m_texImageProcessed(0),
- m_shaderDisplay(0),
- m_shaderComputeV(0),
- m_shaderComputeH(0),
- m_blurRadius(0.0f),
- m_animate(true),
- m_vao(0)
{
const float animationStart = 0.0;
const float animationEnd = 10.0;
@@ -324,27 +315,18 @@ void GLWindow::initializeGL()
<< ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
<< " context";
- if (m_texImageInput) {
- delete m_texImageInput;
- m_texImageInput = 0;
- }
QImage img(":/Qt-logo-medium.png");
Q_ASSERT(!img.isNull());
+ delete m_texImageInput;
m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
- if (m_texImageTmp) {
- delete m_texImageTmp;
- m_texImageTmp = 0;
- }
+ delete m_texImageTmp;
m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageTmp->setFormat(m_texImageInput->format());
m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
- if (m_texImageProcessed) {
- delete m_texImageProcessed;
- m_texImageProcessed = 0;
- }
+ delete m_texImageProcessed;
m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageProcessed->setFormat(m_texImageInput->format());
m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
@@ -354,10 +336,7 @@ void GLWindow::initializeGL()
m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
- if (m_shaderDisplay) {
- delete m_shaderDisplay;
- m_shaderDisplay = 0;
- }
+ delete m_shaderDisplay;
m_shaderDisplay = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax.
@@ -365,18 +344,12 @@ void GLWindow::initializeGL()
m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
m_shaderDisplay->link();
- if (m_shaderComputeV) {
- delete m_shaderComputeV;
- m_shaderComputeV = 0;
- }
+ delete m_shaderComputeV;
m_shaderComputeV = new QOpenGLShaderProgram;
m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
m_shaderComputeV->link();
- if (m_shaderComputeH) {
- delete m_shaderComputeH;
- m_shaderComputeH = 0;
- }
+ delete m_shaderComputeH;
m_shaderComputeH = new QOpenGLShaderProgram;
m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
m_shaderComputeH->link();
diff --git a/examples/opengl/computegles31/glwindow.h b/examples/opengl/computegles31/glwindow.h
index f243858a45..5375fbb488 100644
--- a/examples/opengl/computegles31/glwindow.h
+++ b/examples/opengl/computegles31/glwindow.h
@@ -90,21 +90,21 @@ protected:
void setAnimating(bool animate);
private:
- QPropertyAnimation *m_animationForward;
- QPropertyAnimation *m_animationBackward;
+ QPropertyAnimation *m_animationForward = nullptr;
+ QPropertyAnimation *m_animationBackward = nullptr;
QSequentialAnimationGroup *m_animationGroup;
- QOpenGLTexture *m_texImageInput;
- QOpenGLTexture *m_texImageTmp;
- QOpenGLTexture *m_texImageProcessed;
- QOpenGLShaderProgram *m_shaderDisplay;
- QOpenGLShaderProgram *m_shaderComputeV;
- QOpenGLShaderProgram *m_shaderComputeH;
+ QOpenGLTexture *m_texImageInput = nullptr;
+ QOpenGLTexture *m_texImageTmp = nullptr;
+ QOpenGLTexture *m_texImageProcessed = nullptr;
+ QOpenGLShaderProgram *m_shaderDisplay = nullptr;
+ QOpenGLShaderProgram *m_shaderComputeV = nullptr;
+ QOpenGLShaderProgram *m_shaderComputeH = nullptr;
QMatrix4x4 m_proj;
QSizeF m_quadSize;
- int m_blurRadius;
- bool m_animate;
- QOpenGLVertexArrayObject *m_vao;
+ int m_blurRadius = 0;
+ bool m_animate = true;
+ QOpenGLVertexArrayObject *m_vao = nullptr;
};
#endif
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp
index 21b7434be6..ea9a7a24cb 100644
--- a/examples/opengl/contextinfo/renderwindow.cpp
+++ b/examples/opengl/contextinfo/renderwindow.cpp
@@ -56,7 +56,7 @@
#include <QOpenGLFunctions>
RenderWindow::RenderWindow(const QSurfaceFormat &format)
- : m_context(0),
+ : m_context(nullptr),
m_initialized(false),
m_forceGLSL110(false),
m_angle(0.0f)
@@ -67,7 +67,7 @@ RenderWindow::RenderWindow(const QSurfaceFormat &format)
m_context->setFormat(requestedFormat());
if (!m_context->create()) {
delete m_context;
- m_context = 0;
+ m_context = nullptr;
}
}
diff --git a/examples/opengl/contextinfo/widget.h b/examples/opengl/contextinfo/widget.h
index 72abe0e647..85d181a229 100644
--- a/examples/opengl/contextinfo/widget.h
+++ b/examples/opengl/contextinfo/widget.h
@@ -64,7 +64,7 @@ class Widget : public QWidget
Q_OBJECT
public:
- explicit Widget(QWidget *parent = 0);
+ explicit Widget(QWidget *parent = nullptr);
private slots:
void start();
diff --git a/examples/opengl/cube/geometryengine.cpp b/examples/opengl/cube/geometryengine.cpp
index 1f9e16a935..24e014201e 100644
--- a/examples/opengl/cube/geometryengine.cpp
+++ b/examples/opengl/cube/geometryengine.cpp
@@ -174,6 +174,6 @@ void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program)
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
// Draw cube geometry using indices from VBO 1
- glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0);
+ glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr);
}
//! [2]
diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp
index 292a4245fa..558ecd1299 100644
--- a/examples/opengl/cube/mainwidget.cpp
+++ b/examples/opengl/cube/mainwidget.cpp
@@ -52,15 +52,7 @@
#include <QMouseEvent>
-#include <math.h>
-
-MainWidget::MainWidget(QWidget *parent) :
- QOpenGLWidget(parent),
- geometries(0),
- texture(0),
- angularSpeed(0)
-{
-}
+#include <cmath>
MainWidget::~MainWidget()
{
diff --git a/examples/opengl/cube/mainwidget.h b/examples/opengl/cube/mainwidget.h
index cd2f8098ad..b6a03d454a 100644
--- a/examples/opengl/cube/mainwidget.h
+++ b/examples/opengl/cube/mainwidget.h
@@ -69,7 +69,7 @@ class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- explicit MainWidget(QWidget *parent = 0);
+ using QOpenGLWidget::QOpenGLWidget;
~MainWidget();
protected:
@@ -87,15 +87,15 @@ protected:
private:
QBasicTimer timer;
QOpenGLShaderProgram program;
- GeometryEngine *geometries;
+ GeometryEngine *geometries = nullptr;
- QOpenGLTexture *texture;
+ QOpenGLTexture *texture = nullptr;
QMatrix4x4 projection;
QVector2D mousePressPosition;
QVector3D rotationAxis;
- qreal angularSpeed;
+ qreal angularSpeed = 0;
QQuaternion rotation;
};
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp
index 318adb5043..543e70f8ac 100644
--- a/examples/opengl/hellogl2/glwidget.cpp
+++ b/examples/opengl/hellogl2/glwidget.cpp
@@ -57,11 +57,7 @@
bool GLWidget::m_transparent = false;
GLWidget::GLWidget(QWidget *parent)
- : QOpenGLWidget(parent),
- m_xRot(0),
- m_yRot(0),
- m_zRot(0),
- m_program(0)
+ : QOpenGLWidget(parent)
{
m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
// --transparent causes the clear color to be transparent. Therefore, on systems that
@@ -133,7 +129,7 @@ void GLWidget::cleanup()
makeCurrent();
m_logoVbo.destroy();
delete m_program;
- m_program = 0;
+ m_program = nullptr;
doneCurrent();
}
@@ -250,8 +246,10 @@ void GLWidget::setupVertexAttribs()
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
- f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ nullptr);
+ f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_logoVbo.release();
}
diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h
index 21dd200dc7..f8526fb7ae 100644
--- a/examples/opengl/hellogl2/glwidget.h
+++ b/examples/opengl/hellogl2/glwidget.h
@@ -65,7 +65,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- GLWidget(QWidget *parent = 0);
+ GLWidget(QWidget *parent = nullptr);
~GLWidget();
static bool isTransparent() { return m_transparent; }
@@ -96,18 +96,18 @@ private:
void setupVertexAttribs();
bool m_core;
- int m_xRot;
- int m_yRot;
- int m_zRot;
+ int m_xRot = 0;
+ int m_yRot = 0;
+ int m_zRot = 0;
QPoint m_lastPos;
Logo m_logo;
QOpenGLVertexArrayObject m_vao;
QOpenGLBuffer m_logoVbo;
- QOpenGLShaderProgram *m_program;
- int m_projMatrixLoc;
- int m_mvMatrixLoc;
- int m_normalMatrixLoc;
- int m_lightPosLoc;
+ QOpenGLShaderProgram *m_program = nullptr;
+ int m_projMatrixLoc = 0;
+ int m_mvMatrixLoc = 0;
+ int m_normalMatrixLoc = 0;
+ int m_lightPosLoc = 0;
QMatrix4x4 m_proj;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
diff --git a/examples/opengl/hellogl2/logo.cpp b/examples/opengl/hellogl2/logo.cpp
index a1ec8eaebe..6fcece16d4 100644
--- a/examples/opengl/hellogl2/logo.cpp
+++ b/examples/opengl/hellogl2/logo.cpp
@@ -52,7 +52,6 @@
#include <qmath.h>
Logo::Logo()
- : m_count(0)
{
m_data.resize(2500 * 6);
diff --git a/examples/opengl/hellogl2/logo.h b/examples/opengl/hellogl2/logo.h
index 9e04a57e86..2f3dc7e649 100644
--- a/examples/opengl/hellogl2/logo.h
+++ b/examples/opengl/hellogl2/logo.h
@@ -69,7 +69,7 @@ private:
void add(const QVector3D &v, const QVector3D &n);
QVector<GLfloat> m_data;
- int m_count;
+ int m_count = 0;
};
#endif // LOGO_H
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
index 6bfdee7785..aa20cd678c 100644
--- a/examples/opengl/hellogl2/mainwindow.cpp
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -72,5 +72,6 @@ void MainWindow::onAddNew()
if (!centralWidget())
setCentralWidget(new Window(this));
else
- QMessageBox::information(0, tr("Cannot add new window"), tr("Already occupied. Undock first."));
+ QMessageBox::information(nullptr, tr("Cannot add new window"),
+ tr("Already occupied. Undock first."));
}
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index c3cd10cbfd..5534f2edea 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -121,7 +121,7 @@ void Window::keyPressEvent(QKeyEvent *e)
void Window::dockUndock()
{
if (parent()) {
- setParent(0);
+ setParent(nullptr);
setAttribute(Qt::WA_DeleteOnClose);
move(QApplication::desktop()->width() / 2 - width() / 2,
QApplication::desktop()->height() / 2 - height() / 2);
@@ -134,10 +134,12 @@ void Window::dockUndock()
dockBtn->setText(tr("Undock"));
mainWindow->setCentralWidget(this);
} else {
- QMessageBox::information(0, tr("Cannot dock"), tr("Main window already closed"));
+ QMessageBox::information(nullptr, tr("Cannot dock"),
+ tr("Main window already closed"));
}
} else {
- QMessageBox::information(0, tr("Cannot dock"), tr("Main window already occupied"));
+ QMessageBox::information(nullptr, tr("Cannot dock"),
+ tr("Main window already occupied"));
}
}
}
diff --git a/examples/opengl/hellogles3/glwindow.cpp b/examples/opengl/hellogles3/glwindow.cpp
index 9458b74810..c644faa9a6 100644
--- a/examples/opengl/hellogles3/glwindow.cpp
+++ b/examples/opengl/hellogles3/glwindow.cpp
@@ -57,19 +57,10 @@
#include <QOpenGLVertexArrayObject>
#include <QOpenGLExtraFunctions>
#include <QPropertyAnimation>
-#include <QPauseAnimation>
#include <QSequentialAnimationGroup>
#include <QTimer>
GLWindow::GLWindow()
- : m_texture(0),
- m_program(0),
- m_vbo(0),
- m_vao(0),
- m_target(0, 0, -1),
- m_uniformsDirty(true),
- m_r(0),
- m_r2(0)
{
m_world.setToIdentity();
m_world.translate(0, 0, -1);
@@ -197,18 +188,12 @@ void GLWindow::initializeGL()
{
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- if (m_texture) {
- delete m_texture;
- m_texture = 0;
- }
QImage img(":/qtlogo.png");
Q_ASSERT(!img.isNull());
+ delete m_texture;
m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored());
- if (m_program) {
- delete m_program;
- m_program = 0;
- }
+ delete m_program;
m_program = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax.
@@ -223,26 +208,21 @@ void GLWindow::initializeGL()
m_lightPosLoc = m_program->uniformLocation("lightPos");
// Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL.
- if (m_vao) {
- delete m_vao;
- m_vao = 0;
- }
+ delete m_vao;
m_vao = new QOpenGLVertexArrayObject;
if (m_vao->create())
m_vao->bind();
- if (m_vbo) {
- delete m_vbo;
- m_vbo = 0;
- }
m_program->bind();
+ delete m_vbo;
m_vbo = new QOpenGLBuffer;
m_vbo->create();
m_vbo->bind();
m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ nullptr);
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_vbo->release();
diff --git a/examples/opengl/hellogles3/glwindow.h b/examples/opengl/hellogles3/glwindow.h
index fba997bee4..dfa0680714 100644
--- a/examples/opengl/hellogles3/glwindow.h
+++ b/examples/opengl/hellogles3/glwindow.h
@@ -90,23 +90,23 @@ public:
private slots:
void startSecondStage();
private:
- QOpenGLTexture *m_texture;
- QOpenGLShaderProgram *m_program;
- QOpenGLBuffer *m_vbo;
- QOpenGLVertexArrayObject *m_vao;
+ QOpenGLTexture *m_texture = nullptr;
+ QOpenGLShaderProgram *m_program = nullptr;
+ QOpenGLBuffer *m_vbo = nullptr;
+ QOpenGLVertexArrayObject *m_vao = nullptr;
Logo m_logo;
- int m_projMatrixLoc;
- int m_camMatrixLoc;
- int m_worldMatrixLoc;
- int m_myMatrixLoc;
- int m_lightPosLoc;
+ int m_projMatrixLoc = 0;
+ int m_camMatrixLoc = 0;
+ int m_worldMatrixLoc = 0;
+ int m_myMatrixLoc = 0;
+ int m_lightPosLoc = 0;
QMatrix4x4 m_proj;
QMatrix4x4 m_world;
QVector3D m_eye;
- QVector3D m_target;
- bool m_uniformsDirty;
- float m_r;
- float m_r2;
+ QVector3D m_target = {0, 0, -1};
+ bool m_uniformsDirty = true;
+ float m_r = 0;
+ float m_r2 = 0;
};
#endif
diff --git a/examples/opengl/qopenglwidget/bubble.cpp b/examples/opengl/qopenglwidget/bubble.cpp
index dbaf460f6f..7e69aac3e7 100644
--- a/examples/opengl/qopenglwidget/bubble.cpp
+++ b/examples/opengl/qopenglwidget/bubble.cpp
@@ -57,15 +57,13 @@ Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
{
innerColor = randomColor();
outerColor = randomColor();
- cache = 0;
updateBrush();
}
//! [0]
void Bubble::updateCache()
{
- if (cache)
- delete cache;
+ delete cache;
cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
cache->fill(0x00000000);
QPainter p(cache);
@@ -80,8 +78,7 @@ void Bubble::updateCache()
Bubble::~Bubble()
{
- if (cache)
- delete cache;
+ delete cache;
}
void Bubble::updateBrush()
diff --git a/examples/opengl/qopenglwidget/bubble.h b/examples/opengl/qopenglwidget/bubble.h
index 7170803b40..833ea02288 100644
--- a/examples/opengl/qopenglwidget/bubble.h
+++ b/examples/opengl/qopenglwidget/bubble.h
@@ -80,7 +80,7 @@ private:
qreal radius;
QColor innerColor;
QColor outerColor;
- QImage *cache;
+ QImage *cache = nullptr;
};
#endif
diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp
index 5057291f12..89c8469662 100644
--- a/examples/opengl/qopenglwidget/glwidget.cpp
+++ b/examples/opengl/qopenglwidget/glwidget.cpp
@@ -68,14 +68,6 @@ const int bubbleNum = 8;
GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
: m_mainWindow(mw),
- m_showBubbles(true),
- m_qtLogo(true),
- m_frames(0),
- m_program1(0),
- m_program2(0),
- m_texture(0),
- m_transparent(false),
- m_btn(0),
m_hasButton(button),
m_background(background)
{
diff --git a/examples/opengl/qopenglwidget/glwidget.h b/examples/opengl/qopenglwidget/glwidget.h
index 0ad2581cb8..99288261c0 100644
--- a/examples/opengl/qopenglwidget/glwidget.h
+++ b/examples/opengl/qopenglwidget/glwidget.h
@@ -98,34 +98,34 @@ private:
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
MainWindow *m_mainWindow;
- qreal m_fAngle;
- qreal m_fScale;
- bool m_showBubbles;
+ qreal m_fAngle = 0;
+ qreal m_fScale = 1;
+ bool m_showBubbles = true;
QVector<QVector3D> m_vertices;
QVector<QVector3D> m_normals;
- bool m_qtLogo;
- QList<Bubble *> m_bubbles;
- int m_frames;
+ bool m_qtLogo = true;
+ QVector<Bubble *> m_bubbles;
+ int m_frames = 0;
QElapsedTimer m_time;
- QOpenGLShader *m_vshader1;
- QOpenGLShader *m_fshader1;
- QOpenGLShader *m_vshader2;
- QOpenGLShader *m_fshader2;
- QOpenGLShaderProgram *m_program1;
- QOpenGLShaderProgram *m_program2;
- QOpenGLTexture *m_texture;
+ QOpenGLShader *m_vshader1 = nullptr;
+ QOpenGLShader *m_fshader1 = nullptr;
+ QOpenGLShader *m_vshader2 = nullptr;
+ QOpenGLShader *m_fshader2 = nullptr;
+ QOpenGLShaderProgram *m_program1 = nullptr;
+ QOpenGLShaderProgram *m_program2 = nullptr;
+ QOpenGLTexture *m_texture = nullptr;
QOpenGLBuffer m_vbo1;
QOpenGLBuffer m_vbo2;
- int m_vertexAttr1;
- int m_normalAttr1;
- int m_matrixUniform1;
- int m_vertexAttr2;
- int m_normalAttr2;
- int m_texCoordAttr2;
- int m_matrixUniform2;
- int m_textureUniform2;
- bool m_transparent;
- QPushButton *m_btn;
+ int m_vertexAttr1 = 0;
+ int m_normalAttr1 = 0;
+ int m_matrixUniform1 = 0;
+ int m_vertexAttr2 = 0;
+ int m_normalAttr2 = 0;
+ int m_texCoordAttr2 = 0;
+ int m_matrixUniform2 = 0;
+ int m_textureUniform2 = 0;
+ bool m_transparent = false;
+ QPushButton *m_btn = nullptr;
bool m_hasButton;
QColor m_background;
};
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 1644233614..307190f308 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -53,17 +53,6 @@
#include <QOpenGLTexture>
#include <QMouseEvent>
-GLWidget::GLWidget(QWidget *parent)
- : QOpenGLWidget(parent),
- clearColor(Qt::black),
- xRot(0),
- yRot(0),
- zRot(0),
- program(0)
-{
- memset(textures, 0, sizeof(textures));
-}
-
GLWidget::~GLWidget()
{
makeCurrent();
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
index 0db2695c6a..585d44dbfe 100644
--- a/examples/opengl/textures/glwidget.h
+++ b/examples/opengl/textures/glwidget.h
@@ -63,7 +63,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- explicit GLWidget(QWidget *parent = 0);
+ using QOpenGLWidget::QOpenGLWidget;
~GLWidget();
QSize minimumSizeHint() const override;
@@ -85,13 +85,13 @@ protected:
private:
void makeObject();
- QColor clearColor;
+ QColor clearColor = Qt::black;
QPoint lastPos;
- int xRot;
- int yRot;
- int zRot;
- QOpenGLTexture *textures[6];
- QOpenGLShaderProgram *program;
+ int xRot = 0;
+ int yRot = 0;
+ int zRot = 0;
+ QOpenGLTexture *textures[6] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
+ QOpenGLShaderProgram *program = nullptr;
QOpenGLBuffer vbo;
};
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
index cc528a734a..2101575fd4 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.cpp
+++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp
@@ -115,12 +115,7 @@ void GLWidget::grabContext()
m_renderer->unlockRenderer();
}
-Renderer::Renderer(GLWidget *w)
- : m_inited(false),
- m_glwidget(w),
- m_exiting(false)
-{
-}
+Renderer::Renderer(GLWidget *w) : m_glwidget(w) {}
void Renderer::paintQtLogo()
{
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
index c33f7e51a7..8dc84dd0b1 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.h
+++ b/examples/opengl/threadedqopenglwidget/glwidget.h
@@ -88,29 +88,29 @@ private:
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
- bool m_inited;
- qreal m_fAngle;
- qreal m_fScale;
+ bool m_inited = false;
+ qreal m_fAngle = 0;
+ qreal m_fScale = 1;
QVector<QVector3D> vertices;
QVector<QVector3D> normals;
QOpenGLShaderProgram program;
QOpenGLBuffer vbo;
- int vertexAttr;
- int normalAttr;
- int matrixUniform;
- GLWidget *m_glwidget;
+ int vertexAttr = 0;
+ int normalAttr = 0;
+ int matrixUniform = 0;
+ GLWidget *m_glwidget = nullptr;
QMutex m_renderMutex;
QElapsedTimer m_elapsed;
QMutex m_grabMutex;
QWaitCondition m_grabCond;
- bool m_exiting;
+ bool m_exiting = false;
};
class GLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
- explicit GLWidget(QWidget *parent = 0);
+ explicit GLWidget(QWidget *parent = nullptr);
~GLWidget();
protected:
diff --git a/examples/sql/masterdetail/mainwindow.cpp b/examples/sql/masterdetail/mainwindow.cpp
index 7f3479619a..2ff9a10d91 100644
--- a/examples/sql/masterdetail/mainwindow.cpp
+++ b/examples/sql/masterdetail/mainwindow.cpp
@@ -320,7 +320,7 @@ QGroupBox* MainWindow::createAlbumGroupBox()
this, &MainWindow::showAlbumDetails);
QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(albumView, 0, 0);
+ layout->addWidget(albumView, 0, { });
box->setLayout(layout);
return box;
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index df77d03567..77549e60f8 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -492,7 +492,7 @@ void Dialog::questionMessage()
void Dialog::warningMessage()
{
QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
- MESSAGE, nullptr, this);
+ MESSAGE, { }, this);
msgBox.setDetailedText(MESSAGE_DETAILS);
msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index af8766a308..d8d09612f6 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -176,16 +176,16 @@
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3
- Two QPushButton objects, \c clearButton and \c quitButton, are instantiated
- and added to \c buttonBox - a QDialogButtonBox object. We use
- QDialogButtonBox here to ensure that the push buttons are presented in a
+ Three QPushButton objects, \c clearButton, \c copyButton, and \c quitButton,
+ are instantiated and added to \c buttonBox - a QDialogButtonBox object. We
+ use QDialogButtonBox here to ensure that the push buttons are presented in a
layout that conforms to the platform's style.
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4
- The \l{QPushButton::clicked()}{clicked()} signals for \c quitButton and
- \c clearButton are connected to \l{QWidget::close()}{close()} and
- \c clear(), respectively.
+ The \l{QPushButton::clicked()}{clicked()} signals for \c copyButton,
+ \c clearButton, and \c quitButton are connected to \c copy(),
+ \c clear() and \l{QWidget::close()}{close()}, respectively.
For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets
vertically. We also set the window title to "Drop Site" and the minimum
diff --git a/examples/widgets/doc/src/icons.qdoc b/examples/widgets/doc/src/icons.qdoc
index 7aae0491d6..24be09a7a9 100644
--- a/examples/widgets/doc/src/icons.qdoc
+++ b/examples/widgets/doc/src/icons.qdoc
@@ -232,8 +232,8 @@
combinations of states and modes for a given icon.
\li \c IconSizeSpinBox is a subclass of QSpinBox that lets the
user enter icon sizes (e.g., "48 x 48").
- \li \c ImageDelegate is a subclass of QItemDelegate that provides
- comboboxes for letting the user set the mode and state
+ \li \c ImageDelegate is a subclass of QStyledItemDelegate that
+ provides comboboxes for letting the user set the mode and state
associated with an image.
\endlist
@@ -468,7 +468,6 @@
loaded into the application.
\snippet widgets/icons/mainwindow.cpp 13
- \snippet widgets/icons/mainwindow.cpp 14
We retrieve the image name using the QFileInfo::baseName()
function that returns the base name of the file without the path,
@@ -486,8 +485,6 @@
Qt::ItemIsEditable flag. Table items are editable by default.
\snippet widgets/icons/mainwindow.cpp 15
- \snippet widgets/icons/mainwindow.cpp 16
- \snippet widgets/icons/mainwindow.cpp 17
Then we create the second and third items in the row making the
default mode Normal and the default state Off. But if the \uicontrol
@@ -498,7 +495,6 @@
example's \c images subdirectory respect this naming convention.
\snippet widgets/icons/mainwindow.cpp 18
- \snippet widgets/icons/mainwindow.cpp 19
In the end we add the items to the associated row, and use the
QTableWidget::openPersistentEditor() function to create
@@ -522,8 +518,6 @@
application.
\snippet widgets/icons/mainwindow.cpp 8
- \snippet widgets/icons/mainwindow.cpp 9
- \snippet widgets/icons/mainwindow.cpp 10
We also extract the image file's name using the
QTableWidgetItem::data() function. This function takes a
@@ -571,24 +565,22 @@
delegate for the table widget. We create a \c ImageDelegate that
we make the item delegate for our view.
- The QItemDelegate class can be used to provide an editor for an item view
+ The QStyledItemDelegate class can be used to provide an editor for an item view
class that is subclassed from QAbstractItemView. Using a delegate
for this purpose allows the editing mechanism to be customized and
developed independently from the model and view.
- In this example we derive \c ImageDelegate from QItemDelegate.
- QItemDelegate usually provides line editors, while our subclass
+ In this example we derive \c ImageDelegate from QStyledItemDelegate.
+ QStyledItemDelegate usually provides line editors, while our subclass
\c ImageDelegate, provides comboboxes for the mode and state
fields.
\snippet widgets/icons/mainwindow.cpp 22
- \snippet widgets/icons/mainwindow.cpp 23
Then we customize the QTableWidget's horizontal header, and hide
the vertical header.
\snippet widgets/icons/mainwindow.cpp 24
- \snippet widgets/icons/mainwindow.cpp 25
At the end, we connect the QTableWidget::itemChanged() signal to
the \c changeIcon() slot to ensure that the preview area is in
@@ -750,23 +742,23 @@
\snippet widgets/icons/imagedelegate.h 0
- The \c ImageDelegate class is a subclass of QItemDelegate. The
- QItemDelegate class provides display and editing facilities for
- data items from a model. A single QItemDelegate object is
+ The \c ImageDelegate class is a subclass of QStyledItemDelegate. The
+ QStyledItemDelegate class provides display and editing facilities for
+ data items from a model. A single QStyledItemDelegate object is
responsible for all items displayed in a item view (in our case,
a QTableWidget).
- A QItemDelegate can be used to provide an editor for an item view
+ A QStyledItemDelegate can be used to provide an editor for an item view
class that is subclassed from QAbstractItemView. Using a delegate
for this purpose allows the editing mechanism to be customized and
developed independently from the model and view.
\snippet widgets/icons/imagedelegate.h 1
- The default implementation of QItemDelegate creates a QLineEdit.
+ The default implementation of QStyledItemDelegate creates a QLineEdit.
Since we want the editor to be a QComboBox, we need to subclass
- QItemDelegate and reimplement the QItemDelegate::createEditor(),
- QItemDelegate::setEditorData() and QItemDelegate::setModelData()
+ QStyledItemDelegate and reimplement the QStyledItemDelegate::createEditor(),
+ QStyledItemDelegate::setEditorData() and QStyledItemDelegate::setModelData()
functions.
\snippet widgets/icons/imagedelegate.h 2
@@ -783,7 +775,7 @@
\snippet widgets/icons/imagedelegate.cpp 1
- The default QItemDelegate::createEditor() implementation returns
+ The default QStyledItemDelegate::createEditor() implementation returns
the widget used to edit the item specified by the model and item
index for editing. The parent widget and style option are used to
control the appearance of the editor widget.
@@ -803,7 +795,7 @@
\snippet widgets/icons/imagedelegate.cpp 2
- The QItemDelegate::setEditorData() function is used by
+ The QStyledItemDelegate::setEditorData() function is used by
QTableWidget to transfer data from a QTableWidgetItem to the
editor. The data is stored as a string; we use
QComboBox::findText() to locate it in the combobox.
@@ -816,7 +808,7 @@
\snippet widgets/icons/imagedelegate.cpp 3
- The QItemDelegate::setEditorData() function is used by QTableWidget
+ The QStyledItemDelegate::setEditorData() function is used by QTableWidget
to transfer data back from the editor to the \l{QTableWidgetItem}.
\snippet widgets/icons/imagedelegate.cpp 4
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index 2dae83bb22..a937e24a4c 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow()
//! [constructor part4]
clearButton = new QPushButton(tr("Clear"));
+ copyButton = new QPushButton(tr("Copy"));
quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole);
+#if !QT_CONFIG(clipboard)
+ copyButton->setVisible(false);
+#endif
+
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear);
+ connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy);
//! [constructor part4]
//! [constructor part5]
@@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow()
void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
{
formatsTable->setRowCount(0);
+ copyButton->setEnabled(false);
if (!mimeData)
return;
//! [updateFormatsTable() part1]
@@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
}
formatsTable->resizeColumnToContents(0);
+#if QT_CONFIG(clipboard)
+ copyButton->setEnabled(formatsTable->rowCount() > 0);
+#endif
}
//! [updateFormatsTable() part4]
+
+void DropSiteWindow::copy()
+{
+#if QT_CONFIG(clipboard)
+ QString text;
+ for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row)
+ text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n';
+ QGuiApplication::clipboard()->setText(text);
+#endif
+}
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
index d80476f369..a40b481637 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
@@ -72,6 +72,7 @@ public:
public slots:
void updateFormatsTable(const QMimeData *mimeData);
+ void copy();
private:
DropArea *dropArea;
@@ -79,6 +80,7 @@ private:
QTableWidget *formatsTable;
QPushButton *clearButton;
+ QPushButton *copyButton;
QPushButton *quitButton;
QDialogButtonBox *buttonBox;
};
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
index d7df2b7b4b..5aa0250a29 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
Q_OBJECT
public:
- explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
+ explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { });
QRectF boundingRect() const override;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
index eadd5fadb8..ad80a238aa 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
@@ -53,7 +53,7 @@
#include <QtWidgets>
SpreadSheetDelegate::SpreadSheetDelegate(QObject *parent)
- : QItemDelegate(parent)
+ : QStyledItemDelegate(parent)
{}
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
index c89459cadf..36c70d2391 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
@@ -51,9 +51,9 @@
#ifndef SPREADSHEETDELEGATE_H
#define SPREADSHEETDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
-class SpreadSheetDelegate : public QItemDelegate
+class SpreadSheetDelegate : public QStyledItemDelegate
{
Q_OBJECT
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.cpp b/examples/widgets/layouts/flowlayout/flowlayout.cpp
index 5c59ae025c..9a488557cf 100644
--- a/examples/widgets/layouts/flowlayout/flowlayout.cpp
+++ b/examples/widgets/layouts/flowlayout/flowlayout.cpp
@@ -123,7 +123,7 @@ QLayoutItem *FlowLayout::takeAt(int index)
//! [6]
Qt::Orientations FlowLayout::expandingDirections() const
{
- return 0;
+ return { };
}
//! [6]
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
index 7f73e46f31..2bd9fd2891 100644
--- a/examples/widgets/mainwindows/mainwindow/colorswatch.h
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h
@@ -62,7 +62,7 @@ class ColorSwatch : public QDockWidget
Q_OBJECT
public:
- explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = 0);
+ explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = { });
void setCustomSizeHint(const QSize &size);
QMenu *colorSwatchMenu() const { return menu; }
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
index a2c9d30ded..3ce9732763 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.h
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h
@@ -65,7 +65,7 @@ public:
explicit MainWindow(const CustomSizeHintMap &customSizeHints,
QWidget *parent = nullptr,
- Qt::WindowFlags flags = 0);
+ Qt::WindowFlags flags = { });
public slots:
void actionTriggered(QAction *action);
diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
index 39c2e43134..4fd251aa1b 100644
--- a/examples/widgets/widgets/icons/imagedelegate.cpp
+++ b/examples/widgets/widgets/icons/imagedelegate.cpp
@@ -55,9 +55,8 @@
//! [0]
ImageDelegate::ImageDelegate(QObject *parent)
- : QItemDelegate(parent)
-{
-}
+ : QStyledItemDelegate(parent)
+{}
//! [0]
//! [1]
diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
index 3b76b78339..9d65304e2c 100644
--- a/examples/widgets/widgets/icons/imagedelegate.h
+++ b/examples/widgets/widgets/icons/imagedelegate.h
@@ -51,10 +51,10 @@
#ifndef IMAGEDELEGATE_H
#define IMAGEDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
//! [0]
-class ImageDelegate : public QItemDelegate
+class ImageDelegate : public QStyledItemDelegate
{
Q_OBJECT
@@ -72,7 +72,7 @@ public:
//! [1] //! [2]
private slots:
void emitCommitData();
-};
//! [2]
+};
#endif
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index f342c18c4c..8e61260041 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -216,16 +216,13 @@ void MainWindow::changeIcon()
QImage image(fileName);
if (!image.isNull())
icon.addPixmap(QPixmap::fromImage(image), mode, state);
-//! [8] //! [9]
+//! [8]
}
-//! [9] //! [10]
}
-//! [10]
-
//! [11]
previewArea->setIcon(icon);
-}
//! [11]
+}
void MainWindow::addSampleImages()
{
@@ -280,17 +277,15 @@ void MainWindow::loadImages(const QStringList &fileNames)
.arg(QDir::toNativeSeparators(fileInfo.absolutePath()), fileInfo.fileName())
.arg(fileInfo2x.exists() ? fileInfo2x.fileName() : tr("<None>"))
.arg(image.width()).arg(image.height());
-//! [13] //! [14]
QTableWidgetItem *fileItem = new QTableWidgetItem(imageName);
fileItem->setData(Qt::UserRole, fileName);
fileItem->setIcon(QPixmap::fromImage(image));
fileItem->setFlags((fileItem->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsEditable);
fileItem->setToolTip(toolTip);
-//! [14]
+//! [13]
//! [15]
QIcon::Mode mode = QIcon::Normal;
-//! [15] //! [16]
QIcon::State state = QIcon::Off;
if (guessModeStateAct->isChecked()) {
if (imageName.contains(QLatin1String("_act"), Qt::CaseInsensitive))
@@ -302,13 +297,11 @@ void MainWindow::loadImages(const QStringList &fileNames)
if (imageName.contains(QLatin1String("_on"), Qt::CaseInsensitive))
state = QIcon::On;
-//! [16] //! [17]
+//! [15]
}
-//! [17]
//! [18]
imagesTable->setItem(row, 0, fileItem);
-//! [18] //! [19]
QTableWidgetItem *modeItem =
new QTableWidgetItem(IconPreviewArea::iconModeNames().at(IconPreviewArea::iconModes().indexOf(mode)));
modeItem->setToolTip(toolTip);
@@ -321,9 +314,9 @@ void MainWindow::loadImages(const QStringList &fileNames)
imagesTable->openPersistentEditor(stateItem);
fileItem->setCheckState(Qt::Checked);
+//! [18]
}
}
-//! [19]
void MainWindow::useHighDpiPixmapsChanged(int checkState)
{
@@ -350,9 +343,7 @@ QWidget *MainWindow::createImagesGroupBox()
//! [21]
//! [22]
- QStringList labels;
-//! [22] //! [23]
- labels << tr("Image") << tr("Mode") << tr("State");
+ const QStringList labels({tr("Image"), tr("Mode"), tr("State")});
imagesTable->horizontalHeader()->setDefaultSectionSize(90);
imagesTable->setColumnCount(3);
@@ -361,18 +352,17 @@ QWidget *MainWindow::createImagesGroupBox()
imagesTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
imagesTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
imagesTable->verticalHeader()->hide();
-//! [23]
+//! [22]
//! [24]
connect(imagesTable, &QTableWidget::itemChanged,
-//! [24] //! [25]
this, &MainWindow::changeIcon);
QVBoxLayout *layout = new QVBoxLayout(imagesGroupBox);
layout->addWidget(imagesTable);
return imagesGroupBox;
-}
//! [25]
+}
//! [26]
QWidget *MainWindow::createIconSizeGroupBox()
@@ -428,8 +418,8 @@ QWidget *MainWindow::createIconSizeGroupBox()
layout->addLayout(otherSizeLayout, 3, 0, 1, 2);
layout->setRowStretch(4, 1);
return iconSizeGroupBox;
-}
//! [27]
+}
void MainWindow::screenChanged()
{