From db63625c50f79a777f1620d38ff14c2b6559cd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Fri, 21 Mar 2025 10:01:34 +0100 Subject: [PATCH] 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 (cherry picked from commit 68a16558171abccd15f5446ac208e105cf337dc0) Reviewed-by: Qt Cherry-pick Bot --- .../snippets/code/src_corelib_thread_qthread.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp index 9852ae4d54c..0c52493a469 100644 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qthread.cpp @@ -2,12 +2,21 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include -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"