Doc: Fix QThread documentation snippet
WorkerThread needs an explicit constructor, otherwise WorkerThread *workerThread = new WorkerThread(this); will fail. While at it, at some infrastructure code so that the .cpp file actually compiles. Change-Id: I35835b1be3da2a1f75222594197f6013b41a7b4a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 68a16558171abccd15f5446ac208e105cf337dc0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ab04b4ba8e
commit
db63625c50
@ -2,12 +2,21 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||||
|
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
class MyObject;
|
class MyObject : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
void startWorkInAThread();
|
||||||
|
private slots:
|
||||||
|
void handleResults(){};
|
||||||
|
};
|
||||||
|
|
||||||
//! [reimpl-run]
|
//! [reimpl-run]
|
||||||
class WorkerThread : public QThread
|
class WorkerThread : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WorkerThread(QObject *parent = nullptr) : QThread(parent) { }
|
||||||
|
protected:
|
||||||
void run() override {
|
void run() override {
|
||||||
QString result;
|
QString result;
|
||||||
/* ... here is the expensive or blocking operation ... */
|
/* ... here is the expensive or blocking operation ... */
|
||||||
@ -66,3 +75,7 @@ signals:
|
|||||||
void operate(const QString &);
|
void operate(const QString &);
|
||||||
};
|
};
|
||||||
//! [worker]
|
//! [worker]
|
||||||
|
|
||||||
|
void Controller::handleResults(const QString &) { }
|
||||||
|
|
||||||
|
#include "src_corelib_thread_qthread.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user