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.

Pick-to: 6.9
Change-Id: I35835b1be3da2a1f75222594197f6013b41a7b4a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Kai Köhne 2025-03-21 10:01:34 +01:00
parent 04fbdd2552
commit 68a1655817

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"