summaryrefslogtreecommitdiffstats
path: root/examples/corelib/threads
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
committerTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
commit6630937e63ae5797487b86743a7733c8ae5cc42c (patch)
tree3d53dacf6430f9099e1fb20835881205de674961 /examples/corelib/threads
parent37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff)
parentc7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff)
Merge commit 'dev' into 'wip/cmake-merge'
Diffstat (limited to 'examples/corelib/threads')
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp11
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.h2
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.cpp2
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.h2
-rw-r--r--examples/corelib/threads/queuedcustomtype/block.cpp8
-rw-r--r--examples/corelib/threads/queuedcustomtype/block.h1
-rw-r--r--examples/corelib/threads/queuedcustomtype/renderthread.h2
-rw-r--r--examples/corelib/threads/queuedcustomtype/window.cpp31
-rw-r--r--examples/corelib/threads/queuedcustomtype/window.h2
-rw-r--r--examples/corelib/threads/semaphores/semaphores.cpp6
-rw-r--r--examples/corelib/threads/semaphores/semaphores.pro3
-rw-r--r--examples/corelib/threads/waitconditions/waitconditions.pro4
12 files changed, 34 insertions, 40 deletions
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
index b3e4af5dc8..71d0abb09f 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
@@ -48,14 +48,13 @@
**
****************************************************************************/
+#include "mandelbrotwidget.h"
+
#include <QPainter>
#include <QKeyEvent>
#include <math.h>
-#include "mandelbrotwidget.h"
-
-
//! [0]
const double DefaultCenterX = -0.637011f;
const double DefaultCenterY = -0.0395159f;
@@ -75,7 +74,8 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent)
pixmapScale = DefaultScale;
curScale = DefaultScale;
- connect(&thread, SIGNAL(renderedImage(QImage,double)), this, SLOT(updatePixmap(QImage,double)));
+ connect(&thread, &RenderThread::renderedImage,
+ this, &MandelbrotWidget::updatePixmap);
setWindowTitle(tr("Mandelbrot"));
#ifndef QT_NO_CURSOR
@@ -117,7 +117,8 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
painter.save();
painter.translate(newX, newY);
painter.scale(scaleFactor, scaleFactor);
- QRectF exposed = painter.matrix().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
+
+ QRectF exposed = painter.transform().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
painter.drawPixmap(exposed, pixmap, exposed);
painter.restore();
}
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
index a04bfa6e81..cb40962535 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
@@ -62,7 +62,7 @@ class MandelbrotWidget : public QWidget
Q_OBJECT
public:
- MandelbrotWidget(QWidget *parent = 0);
+ MandelbrotWidget(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event) override;
diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp
index c57b696e25..eee44c7242 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.cpp
+++ b/examples/corelib/threads/mandelbrot/renderthread.cpp
@@ -50,7 +50,7 @@
#include "renderthread.h"
-#include <QtWidgets>
+#include <QImage>
#include <cmath>
//! [0]
diff --git a/examples/corelib/threads/mandelbrot/renderthread.h b/examples/corelib/threads/mandelbrot/renderthread.h
index b5e9226fb8..4f0394d554 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.h
+++ b/examples/corelib/threads/mandelbrot/renderthread.h
@@ -66,7 +66,7 @@ class RenderThread : public QThread
Q_OBJECT
public:
- RenderThread(QObject *parent = 0);
+ RenderThread(QObject *parent = nullptr);
~RenderThread();
void render(double centerX, double centerY, double scaleFactor, QSize resultSize);
diff --git a/examples/corelib/threads/queuedcustomtype/block.cpp b/examples/corelib/threads/queuedcustomtype/block.cpp
index a5058cc5ae..9cfad8673c 100644
--- a/examples/corelib/threads/queuedcustomtype/block.cpp
+++ b/examples/corelib/threads/queuedcustomtype/block.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QColor>
-#include <QRect>
#include "block.h"
Block::Block()
@@ -57,9 +55,8 @@ Block::Block()
}
Block::Block(const Block &other)
+ : m_rect(other.m_rect), m_color(other.m_color)
{
- m_rect = other.m_rect;
- m_color = other.m_color;
}
Block::~Block()
@@ -67,9 +64,8 @@ Block::~Block()
}
Block::Block(const QRect &rect, const QColor &color)
+ : m_rect(rect), m_color(color)
{
- m_rect = rect;
- m_color = color;
}
QColor Block::color() const
diff --git a/examples/corelib/threads/queuedcustomtype/block.h b/examples/corelib/threads/queuedcustomtype/block.h
index 547cc10f0a..eef48b25c2 100644
--- a/examples/corelib/threads/queuedcustomtype/block.h
+++ b/examples/corelib/threads/queuedcustomtype/block.h
@@ -52,7 +52,6 @@
#define BLOCK_H
#include <QColor>
-#include <QDebug>
#include <QMetaType>
#include <QRect>
diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.h b/examples/corelib/threads/queuedcustomtype/renderthread.h
index 318ef293b4..9375b60e74 100644
--- a/examples/corelib/threads/queuedcustomtype/renderthread.h
+++ b/examples/corelib/threads/queuedcustomtype/renderthread.h
@@ -62,7 +62,7 @@ class RenderThread : public QThread
Q_OBJECT
public:
- RenderThread(QObject *parent = 0);
+ RenderThread(QObject *parent = nullptr);
~RenderThread();
void processImage(const QImage &image);
diff --git a/examples/corelib/threads/queuedcustomtype/window.cpp b/examples/corelib/threads/queuedcustomtype/window.cpp
index 2cefba1e17..183d9824cb 100644
--- a/examples/corelib/threads/queuedcustomtype/window.cpp
+++ b/examples/corelib/threads/queuedcustomtype/window.cpp
@@ -48,30 +48,34 @@
**
****************************************************************************/
-#include <QtWidgets>
#include "window.h"
+#include <QtWidgets>
//! [Window constructor start]
-Window::Window()
+Window::Window(QWidget *parent)
+ : QWidget(parent), thread(new RenderThread(this))
{
- thread = new RenderThread();
//! [Window constructor start] //! [set up widgets and connections]
- label = new QLabel();
+ label = new QLabel(this);
label->setAlignment(Qt::AlignCenter);
- loadButton = new QPushButton(tr("&Load image..."));
- resetButton = new QPushButton(tr("&Stop"));
+ loadButton = new QPushButton(tr("&Load image..."), this);
+ resetButton = new QPushButton(tr("&Stop"), this);
resetButton->setEnabled(false);
- connect(loadButton, SIGNAL(clicked()), this, SLOT(loadImage()));
- connect(resetButton, SIGNAL(clicked()), thread, SLOT(stopProcess()));
- connect(thread, SIGNAL(finished()), this, SLOT(resetUi()));
+ connect(loadButton, &QPushButton::clicked,
+ this, QOverload<>::of(&Window::loadImage));
+ connect(resetButton, &QPushButton::clicked,
+ thread, &RenderThread::stopProcess);
+ connect(thread, &RenderThread::finished,
+ this, &Window::resetUi);
//! [set up widgets and connections] //! [connecting signal with custom type]
- connect(thread, SIGNAL(sendBlock(Block)), this, SLOT(addBlock(Block)));
+ connect(thread, &RenderThread::sendBlock,
+ this, &Window::addBlock);
//! [connecting signal with custom type]
- QHBoxLayout *buttonLayout = new QHBoxLayout();
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(loadButton);
buttonLayout->addWidget(resetButton);
@@ -89,9 +93,10 @@ Window::Window()
void Window::loadImage()
{
QStringList formats;
- foreach (QByteArray format, QImageReader::supportedImageFormats())
+ const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
+ for (const QByteArray &format : supportedFormats)
if (format.toLower() == format)
- formats.append("*." + format);
+ formats.append(QLatin1String("*.") + QString::fromLatin1(format));
QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"),
path, tr("Image files (%1)").arg(formats.join(' ')));
diff --git a/examples/corelib/threads/queuedcustomtype/window.h b/examples/corelib/threads/queuedcustomtype/window.h
index c472c0fea7..4215dfd5a7 100644
--- a/examples/corelib/threads/queuedcustomtype/window.h
+++ b/examples/corelib/threads/queuedcustomtype/window.h
@@ -65,7 +65,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window();
+ Window(QWidget *parent = nullptr);
void loadImage(const QImage &image);
public slots:
diff --git a/examples/corelib/threads/semaphores/semaphores.cpp b/examples/corelib/threads/semaphores/semaphores.cpp
index 145624bb0b..a245b9906b 100644
--- a/examples/corelib/threads/semaphores/semaphores.cpp
+++ b/examples/corelib/threads/semaphores/semaphores.cpp
@@ -94,12 +94,6 @@ public:
}
fprintf(stderr, "\n");
}
-
-signals:
- void stringConsumed(const QString &text);
-
-protected:
- bool finish;
};
//! [4]
diff --git a/examples/corelib/threads/semaphores/semaphores.pro b/examples/corelib/threads/semaphores/semaphores.pro
index 69154e57eb..de909508c4 100644
--- a/examples/corelib/threads/semaphores/semaphores.pro
+++ b/examples/corelib/threads/semaphores/semaphores.pro
@@ -1,8 +1,7 @@
SOURCES += semaphores.cpp
QT = core
-CONFIG -= app_bundle
-CONFIG += console
+CONFIG += cmdline
# install
target.path = $$[QT_INSTALL_EXAMPLES]/corelib/threads/semaphores
diff --git a/examples/corelib/threads/waitconditions/waitconditions.pro b/examples/corelib/threads/waitconditions/waitconditions.pro
index 2dbe7df68a..19b56a246d 100644
--- a/examples/corelib/threads/waitconditions/waitconditions.pro
+++ b/examples/corelib/threads/waitconditions/waitconditions.pro
@@ -1,6 +1,6 @@
QT = core
-CONFIG -= moc app_bundle
-CONFIG += console
+CONFIG -= moc
+CONFIG += cmdline
SOURCES += waitconditions.cpp