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 | |
13 | using namespace ThreadWeaver; |
14 | |
15 | //@@snippet_begin(sample-helloworldraw-class) |
16 | class QDebugJob : public Job |
17 | { |
18 | public: |
19 | QDebugJob(const char *message = nullptr) |
20 | : m_message(message) |
21 | { |
22 | } |
23 | |
24 | protected: |
25 | void run(JobPointer, Thread *) override |
26 | { |
27 | qDebug() << m_message; |
28 | } |
29 | |
30 | private: |
31 | const char *m_message; |
32 | }; |
33 | //@@snippet_end |
34 | |
35 | //@@snippet_begin(sample-helloworldraw-main) |
36 | int main(int argc, char **argv) |
37 | { |
38 | QCoreApplication app(argc, argv); |
39 | // Allocate jobs as local variables: |
40 | QDebugJob j1("Hello" ); |
41 | QDebugJob j2("World!" ); |
42 | JobPointer j3(new QDebugJob("This is..." )); |
43 | Job *j4 = new QDebugJob("ThreadWeaver!" ); |
44 | // Queue the Job using the default Queue stream: |
45 | stream() << j1 << j2 // local variables |
46 | << j3 // a shared pointer |
47 | << j4; // a raw pointer |
48 | // Wait for finish(), because job is destroyed |
49 | // before the global queue: |
50 | Queue::instance()->finish(); |
51 | } |
52 | //@@snippet_end |
53 | |