Qt 4.8
qthread.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTHREAD_H
43 #define QTHREAD_H
44 
45 #include <QtCore/qobject.h>
46 
47 #include <limits.h>
48 
50 
52 
53 QT_MODULE(Core)
54 
55 class QThreadData;
56 class QThreadPrivate;
57 
58 #ifndef QT_NO_THREAD
60 {
61 public:
62  static Qt::HANDLE currentThreadId();
63  static QThread *currentThread();
64  static int idealThreadCount();
65  static void yieldCurrentThread();
66 
67  explicit QThread(QObject *parent = 0);
68  ~QThread();
69 
70  enum Priority {
72 
78 
80 
81  InheritPriority
82  };
83 
84  void setPriority(Priority priority);
85  Priority priority() const;
86 
87  bool isFinished() const;
88  bool isRunning() const;
89 
90  void setStackSize(uint stackSize);
91  uint stackSize() const;
92 
93  void exit(int retcode = 0);
94 
95 public Q_SLOTS:
96  void start(Priority = InheritPriority);
97  void terminate();
98  void quit();
99 
100 public:
101  // default argument causes thread to block indefinately
102  bool wait(unsigned long time = ULONG_MAX);
103 
104 Q_SIGNALS:
105  void started();
106  void finished();
107  void terminated();
108 
109 protected:
110  virtual void run();
111  int exec();
112 
113  static void setTerminationEnabled(bool enabled = true);
114 
115  static void sleep(unsigned long);
116  static void msleep(unsigned long);
117  static void usleep(unsigned long);
118 
119 public:
120 #ifdef QT3_SUPPORT
121  inline QT3_SUPPORT bool finished() const { return isFinished(); }
122  inline QT3_SUPPORT bool running() const { return isRunning(); }
123 #endif
124 
125 protected:
126  QThread(QThreadPrivate &dd, QObject *parent = 0);
127 
128 private:
129  Q_OBJECT
131 
132  static void initialize();
133  static void cleanup();
134 
135  friend class QCoreApplication;
136  friend class QThreadData;
137 };
138 
139 #else // QT_NO_THREAD
140 
141 class Q_CORE_EXPORT QThread : public QObject
142 {
143 public:
144  static Qt::HANDLE currentThreadId() { return Qt::HANDLE(currentThread()); }
145  static QThread* currentThread();
146 
147 protected:
148  QThread(QThreadPrivate &dd, QObject *parent = 0);
149 
150 private:
151  explicit QThread(QObject *parent = 0);
152  static QThread *instance;
153 
154  friend class QCoreApplication;
155  friend class QThreadData;
156  friend class QAdoptedThread;
158 };
159 
160 #endif // QT_NO_THREAD
161 
163 
165 
166 #endif // QTHREAD_H
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Priority
This enum type indicates how the operating system should schedule newly created threads.
Definition: qthread.h:70
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
unsigned int uint
Definition: qglobal.h:996
void * HANDLE
Definition: qnamespace.h:1671
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QCoreApplication class provides an event loop for console Qt applications.
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static void cleanup()
Definition: qpicture.cpp:1508
QFuture< T > run(Function function,...)
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
#define QT_END_HEADER
Definition: qglobal.h:137
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
#define enabled