File indexing completed on 2024-05-12 15:50:10
0001 /* -*- C++ -*- 0002 This file is part of ThreadWeaver. 0003 0004 SPDX-FileCopyrightText: 2005-2014 Mirko Boehm <mirko@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include <QtCore> 0010 #include <ThreadWeaver/ThreadWeaver> 0011 0012 using namespace ThreadWeaver; 0013 0014 //@@snippet_begin(sample-helloworldraw-class) 0015 class QDebugJob : public Job 0016 { 0017 public: 0018 QDebugJob(const char *message = nullptr) 0019 : m_message(message) 0020 { 0021 } 0022 0023 protected: 0024 void run(JobPointer, Thread *) override 0025 { 0026 qDebug() << m_message; 0027 } 0028 0029 private: 0030 const char *m_message; 0031 }; 0032 //@@snippet_end 0033 0034 //@@snippet_begin(sample-helloworldraw-main) 0035 int main(int argc, char **argv) 0036 { 0037 QCoreApplication app(argc, argv); 0038 // Allocate jobs as local variables: 0039 QDebugJob j1("Hello"); 0040 QDebugJob j2("World!"); 0041 JobPointer j3(new QDebugJob("This is...")); 0042 Job *j4 = new QDebugJob("ThreadWeaver!"); 0043 // Queue the Job using the default Queue stream: 0044 stream() << j1 << j2 // local variables 0045 << j3 // a shared pointer 0046 << j4; // a raw pointer 0047 // Wait for finish(), because job is destroyed 0048 // before the global queue: 0049 Queue::instance()->finish(); 0050 } 0051 //@@snippet_end