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