- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qthread.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QTHREAD_H
    00043 #define QTHREAD_H
    00044
    00045 #include <QtCore/qobject.h>
    00046
    00047 #include <limits.h>
    00048
    00049 QT_BEGIN_HEADER
    00050
    00051 QT_BEGIN_NAMESPACE
    00052
    00053 QT_MODULE(Core)
    00054
    00055 class QThreadData;
    00056 class QThreadPrivate;
    00057
    00058 #ifndef QT_NO_THREAD
    00059 class Q_CORE_EXPORT QThread : public QObject
    00060 {
    00061 public:
    00062     static Qt::HANDLE currentThreadId();
    00063     static QThread *currentThread();
    00064     static int idealThreadCount();
    00065     static void yieldCurrentThread();
    00066
    00067     explicit QThread(QObject *parent = 0);
    00068     ~QThread();
    00069
    00070     enum Priority {
    00071         IdlePriority,
    00072
    00073         LowestPriority,
    00074         LowPriority,
    00075         NormalPriority,
    00076         HighPriority,
    00077         HighestPriority,
    00078
    00079         TimeCriticalPriority,
    00080
    00081         InheritPriority
    00082     };
    00083
    00084     void setPriority(Priority priority);
    00085     Priority priority() const;
    00086
    00087     bool isFinished() const;
    00088     bool isRunning() const;
    00089
    00090     void setStackSize(uint stackSize);
    00091     uint stackSize() const;
    00092
    00093     void exit(int retcode = 0);
    00094
    00095 public Q_SLOTS:
    00096     void start(Priority = InheritPriority);
    00097     void terminate();
    00098     void quit();
    00099
    00100 public:
    00101     // default argument causes thread to block indefinately
    00102     bool wait(unsigned long time = ULONG_MAX);
    00103
    00104 Q_SIGNALS:
    00105     void started();
    00106     void finished();
    00107     void terminated();
    00108
    00109 protected:
    00110     virtual void run();
    00111     int exec();
    00112
    00113     static void setTerminationEnabled(bool enabled = true);
    00114
    00115     static void sleep(unsigned long);
    00116     static void msleep(unsigned long);
    00117     static void usleep(unsigned long);
    00118
    00119 #ifdef QT3_SUPPORT
    00120 public:
    00121     inline QT3_SUPPORT bool finished() const { return isFinished(); }
    00122     inline QT3_SUPPORT bool running() const { return isRunning(); }
    00123 #endif
    00124
    00125 protected:
    00126     QThread(QThreadPrivate &dd, QObject *parent = 0);
    00127
    00128 private:
    00129     Q_OBJECT
    00130     Q_DECLARE_PRIVATE(QThread)
    00131
    00132     static void initialize();
    00133     static void cleanup();
    00134
    00135     friend class QCoreApplication;
    00136     friend class QThreadData;
    00137 };
    00138
    00139 #else // QT_NO_THREAD
    00140
    00141 class Q_CORE_EXPORT QThread : public QObject
    00142 {
    00143 public:
    00144     static Qt::HANDLE currentThreadId() { return Qt::HANDLE(currentThread()); }
    00145     static QThread* currentThread();
    00146
    00147 protected:
    00148     QThread(QThreadPrivate &dd, QObject *parent = 0);
    00149
    00150 private:
    00151     explicit QThread(QObject *parent = 0);
    00152     static QThread *instance;
    00153
    00154     friend class QCoreApplication;
    00155     friend class QThreadData;
    00156     friend class QAdoptedThread;
    00157     Q_DECLARE_PRIVATE(QThread)
    00158 };
    00159
    00160 #endif // QT_NO_THREAD
    00161
    00162 QT_END_NAMESPACE
    00163
    00164 QT_END_HEADER
    00165
    00166 #endif // QTHREAD_H