1/* -*- C++ -*-
2 This file is part of ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2014 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include <ThreadWeaver/ThreadWeaver>
10
11#include <QCoreApplication>
12#include <QDebug>
13
14using namespace ThreadWeaver;
15
16//@@snippet_begin(sample-helloworldraw-class)
17class QDebugJob : public Job
18{
19public:
20 QDebugJob(const char *message = nullptr)
21 : m_message(message)
22 {
23 }
24
25protected:
26 void run(JobPointer, Thread *) override
27 {
28 qDebug() << m_message;
29 }
30
31private:
32 const char *m_message;
33};
34//@@snippet_end
35
36//@@snippet_begin(sample-helloworldraw-main)
37int main(int argc, char **argv)
38{
39 QCoreApplication app(argc, argv);
40 // Allocate jobs as local variables:
41 QDebugJob j1("Hello");
42 QDebugJob j2("World!");
43 JobPointer j3(new QDebugJob("This is..."));
44 Job *j4 = new QDebugJob("ThreadWeaver!");
45 // Queue the Job using the default Queue stream:
46 stream() << j1 << j2 // local variables
47 << j3 // a shared pointer
48 << j4; // a raw pointer
49 // Wait for finish(), because job is destroyed
50 // before the global queue:
51 Queue::instance()->finish();
52}
53//@@snippet_end
54

source code of threadweaver/examples/HelloWorldRaw/HelloWorldRaw.cpp