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:
Kai Köhne 2025-03-21 10:01:34 +01:00 committed by Qt Cherry-pick Bot
parent ab04b4ba8e
commit db63625c50

View File

@ -2,12 +2,21 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QThread>
class MyObject;
class MyObject : public QObject
{
Q_OBJECT
void startWorkInAThread();
private slots:
void handleResults(){};
};
//! [reimpl-run]
class WorkerThread : public QThread
{
Q_OBJECT
public:
explicit WorkerThread(QObject *parent = nullptr) : QThread(parent) { }
protected:
void run() override {
QString result;
/* ... here is the expensive or blocking operation ... */
@ -66,3 +75,7 @@ signals:
void operate(const QString &);
};
//! [worker]
void Controller::handleResults(const QString &) { }
#include "src_corelib_thread_qthread.moc"