Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 908

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qthread.cpp -->
  <title>QThread Class | Qt Core 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QThread</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#public-slots">Public Slots</a></li>
<li class="level1"><a href="#signals">Signals</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#static-protected-members">Static Protected Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#managing-threads">Managing Threads</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QThread Class</h1>
<!-- $$$QThread-brief -->
<p>The <a href="qthread.html">QThread</a> class provides a platform-independent way to manage threads. <a href="#details">More...</a></p>
<!-- @@@QThread -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QThread&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qthread-members.html">List of all members, including inherited members</a></li>
<li><a href="qthread-obsolete.html">Obsolete members</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#Priority-enum">Priority</a></b> { IdlePriority, LowestPriority, LowPriority, NormalPriority, ..., InheritPriority }</td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#QThread">QThread</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#dtor.QThread">~QThread</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QAbstractEventDispatcher *</td><td class="memItemRight bottomAlign"><b><a href="qthread.html#eventDispatcher">eventDispatcher</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#exit">exit</a></b>(int <i>returnCode</i> = 0)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#isFinished">isFinished</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#isInterruptionRequested">isInterruptionRequested</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#isRunning">isRunning</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#loopLevel">loopLevel</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QThread::Priority </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#priority">priority</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#requestInterruption">requestInterruption</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setEventDispatcher">setEventDispatcher</a></b>(QAbstractEventDispatcher *<i>eventDispatcher</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setPriority">setPriority</a></b>(QThread::Priority <i>priority</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setStackSize">setStackSize</a></b>(uint <i>stackSize</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> uint </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#stackSize">stackSize</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#wait">wait</a></b>(unsigned long <i>time</i> = ULONG_MAX)</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#event">event</a></b>(QEvent *<i>event</i>) override</td></tr>
</table></div>
<ul>
<li class="fn">32 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="public-slots"></a>
<h2 id="public-slots">Public Slots</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#quit">quit</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#start">start</a></b>(QThread::Priority <i>priority</i> = InheritPriority)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#terminate">terminate</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
</ul>
<a name="signals"></a>
<h2 id="signals">Signals</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#finished">finished</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#started">started</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">2 signals inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QThread *</td><td class="memItemRight bottomAlign"><b><a href="qthread.html#create">create</a></b>(Function &amp;&amp;<i>f</i>, Args &amp;&amp;... <i>args</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QThread *</td><td class="memItemRight bottomAlign"><b><a href="qthread.html#create-1">create</a></b>(Function &amp;&amp;<i>f</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QThread *</td><td class="memItemRight bottomAlign"><b><a href="qthread.html#currentThread">currentThread</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Qt::HANDLE </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#currentThreadId">currentThreadId</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#idealThreadCount">idealThreadCount</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#msleep">msleep</a></b>(unsigned long <i>msecs</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#sleep">sleep</a></b>(unsigned long <i>secs</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#usleep">usleep</a></b>(unsigned long <i>usecs</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#yieldCurrentThread">yieldCurrentThread</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">10 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#exec">exec</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#run">run</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">9 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="static-protected-members"></a>
<h2 id="static-protected-members">Static Protected Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a></b>(bool <i>enabled</i> = true)</td></tr>
</table></div>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QThread-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qthread.html">QThread</a> class provides a platform-independent way to manage threads.</p>
<p>A <a href="qthread.html">QThread</a> object manages one thread of control within the program. QThreads begin executing in <a href="qthread.html#run">run</a>(). By default, <a href="qthread.html#run">run</a>() starts the event loop by calling <a href="qthread.html#exec">exec</a>() and runs a Qt event loop inside the thread.</p>
<p>You can use worker objects by moving them to the thread using <a href="qobject.html#moveToThread">QObject::moveToThread</a>().</p>
<pre class="cpp">

  <span class="keyword">class</span> Worker : <span class="keyword">public</span> <span class="type"><a href="qobject.html#QObject">QObject</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> doWork(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>parameter) {
          <span class="type"><a href="qstring.html">QString</a></span> result;
          <span class="comment">/* ... here is the expensive or blocking operation ... */</span>
          <span class="keyword">emit</span> resultReady(result);
      }

  <span class="keyword">signals</span>:
      <span class="type">void</span> resultReady(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>result);
  };

  <span class="keyword">class</span> Controller : <span class="keyword">public</span> <span class="type"><a href="qobject.html#QObject">QObject</a></span>
  {
      Q_OBJECT
      <span class="type"><a href="qthread.html#QThread">QThread</a></span> workerThread;
  <span class="keyword">public</span>:
      Controller() {
          Worker <span class="operator">*</span>worker <span class="operator">=</span> <span class="keyword">new</span> Worker;
          worker<span class="operator">-</span><span class="operator">&gt;</span>moveToThread(<span class="operator">&amp;</span>workerThread);
          connect(<span class="operator">&amp;</span>workerThread<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qthread.html#QThread">QThread</a></span><span class="operator">::</span>finished<span class="operator">,</span> worker<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qobject.html#QObject">QObject</a></span><span class="operator">::</span>deleteLater);
          connect(<span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Controller<span class="operator">::</span>operate<span class="operator">,</span> worker<span class="operator">,</span> <span class="operator">&amp;</span>Worker<span class="operator">::</span>doWork);
          connect(worker<span class="operator">,</span> <span class="operator">&amp;</span>Worker<span class="operator">::</span>resultReady<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Controller<span class="operator">::</span>handleResults);
          workerThread<span class="operator">.</span>start();
      }
      <span class="operator">~</span>Controller() {
          workerThread<span class="operator">.</span>quit();
          workerThread<span class="operator">.</span>wait();
      }
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> handleResults(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>);
  <span class="keyword">signals</span>:
      <span class="type">void</span> operate(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>);
  };

</pre>
<p>The code inside the Worker's slot would then execute in a separate thread. However, you are free to connect the Worker's slots to any signal, from any object, in any thread. It is safe to connect signals and slots across different threads, thanks to a mechanism called <a href="qt.html#ConnectionType-enum">queued connections</a>.</p>
<p>Another way to make code run in a separate thread, is to subclass <a href="qthread.html">QThread</a> and reimplement <a href="qthread.html#run">run</a>(). For example:</p>
<pre class="cpp">

  <span class="keyword">class</span> WorkerThread : <span class="keyword">public</span> <span class="type"><a href="qthread.html#QThread">QThread</a></span>
  {
      Q_OBJECT
      <span class="type">void</span> run() override {
          <span class="type"><a href="qstring.html">QString</a></span> result;
          <span class="comment">/* ... here is the expensive or blocking operation ... */</span>
          <span class="keyword">emit</span> resultReady(result);
      }
  <span class="keyword">signals</span>:
      <span class="type">void</span> resultReady(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>s);
  };

  <span class="type">void</span> MyObject<span class="operator">::</span>startWorkInAThread()
  {
      WorkerThread <span class="operator">*</span>workerThread <span class="operator">=</span> <span class="keyword">new</span> WorkerThread(<span class="keyword">this</span>);
      connect(workerThread<span class="operator">,</span> <span class="operator">&amp;</span>WorkerThread<span class="operator">::</span>resultReady<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MyObject<span class="operator">::</span>handleResults);
      connect(workerThread<span class="operator">,</span> <span class="operator">&amp;</span>WorkerThread<span class="operator">::</span>finished<span class="operator">,</span> workerThread<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qobject.html#QObject">QObject</a></span><span class="operator">::</span>deleteLater);
      workerThread<span class="operator">-</span><span class="operator">&gt;</span>start();
  }

</pre>
<p>In that example, the thread will exit after the run function has returned. There will not be any event loop running in the thread unless you call <a href="qthread.html#exec">exec</a>().</p>
<p>It is important to remember that a <a href="qthread.html">QThread</a> instance <a href="qobject.html#thread-affinity">lives in</a> the old thread that instantiated it, not in the new thread that calls <a href="qthread.html#run">run</a>(). This means that all of <a href="qthread.html">QThread</a>'s queued slots and <a href="qmetaobject.html#invokeMethod">invoked methods</a> will execute in the old thread. Thus, a developer who wishes to invoke slots in the new thread must use the worker-object approach; new slots should not be implemented directly into a subclassed <a href="qthread.html">QThread</a>.</p>
<p>Unlike queued slots or invoked methods, methods called directly on the <a href="qthread.html">QThread</a> object will execute in the thread that calls the method. When subclassing <a href="qthread.html">QThread</a>, keep in mind that the constructor executes in the old thread while <a href="qthread.html#run">run</a>() executes in the new thread. If a member variable is accessed from both functions, then the variable is accessed from two different threads. Check that it is safe to do so.</p>
<p><b>Note: </b>Care must be taken when interacting with objects across different threads. See Synchronizing Threads for details.</p><a name="managing-threads"></a>
<h3 id="managing-threads">Managing Threads</h3>
<p><a href="qthread.html">QThread</a> will notifiy you via a signal when the thread is <a href="qthread.html#started">started</a>() and <a href="qthread.html#finished">finished</a>(), or you can use <a href="qthread.html#isFinished">isFinished</a>() and <a href="qthread.html#isRunning">isRunning</a>() to query the state of the thread.</p>
<p>You can stop the thread by calling <a href="qthread.html#exit">exit</a>() or <a href="qthread.html#quit">quit</a>(). In extreme cases, you may want to forcibly <a href="qthread.html#terminate">terminate</a>() an executing thread. However, doing so is dangerous and discouraged. Please read the documentation for <a href="qthread.html#terminate">terminate</a>() and <a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a>() for detailed information.</p>
<p>From Qt 4.8 onwards, it is possible to deallocate objects that live in a thread that has just ended, by connecting the <a href="qthread.html#finished">finished</a>() signal to <a href="qobject.html#deleteLater">QObject::deleteLater</a>().</p>
<p>Use <a href="qthread.html#wait">wait</a>() to block the calling thread, until the other thread has finished execution (or until a specified time has passed).</p>
<p><a href="qthread.html">QThread</a> also provides static, platform independent sleep functions: <a href="qthread.html#sleep">sleep</a>(), <a href="qthread.html#msleep">msleep</a>(), and <a href="qthread.html#usleep">usleep</a>() allow full second, millisecond, and microsecond resolution respectively. These functions were made public in Qt 5.0&#x2e;</p>
<p><b>Note: </b><a href="qthread.html#wait">wait</a>() and the <a href="qthread.html#sleep">sleep</a>() functions should be unnecessary in general, since Qt is an event-driven framework. Instead of <a href="qthread.html#wait">wait</a>(), consider listening for the <a href="qthread.html#finished">finished</a>() signal. Instead of the <a href="qthread.html#sleep">sleep</a>() functions, consider using <a href="qtimer.html">QTimer</a>.</p><p>The static functions <a href="qthread.html#currentThreadId">currentThreadId</a>() and <a href="qthread.html#currentThread">currentThread</a>() return identifiers for the currently executing thread. The former returns a platform specific ID for the thread; the latter returns a <a href="qthread.html">QThread</a> pointer.</p>
<p>To choose the name that your thread will be given (as identified by the command <code>ps -L</code> on Linux, for example), you can call <a href="qobject.html#objectName-prop">setObjectName()</a> before starting the thread. If you don't call <a href="qobject.html#objectName-prop">setObjectName()</a>, the name given to your thread will be the class name of the runtime type of your thread object (for example, <code>&quot;RenderThread&quot;</code> in the case of the <a href="qtcore-threads-mandelbrot-example.html">Mandelbrot Example</a>, as that is the name of the <a href="qthread.html">QThread</a> subclass). Note that this is currently not available with release builds on Windows.</p>
</div>
<p><b>See also </b>Thread Support in Qt, <a href="qthreadstorage.html">QThreadStorage</a>, Synchronizing Threads, <a href="qtcore-threads-mandelbrot-example.html">Mandelbrot Example</a>, <a href="qtcore-threads-semaphores-example.html">Semaphores Example</a>, and <a href="qtcore-threads-waitconditions-example.html">Wait Conditions Example</a>.</p>
<!-- @@@QThread -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Priority$$$IdlePriority$$$LowestPriority$$$LowPriority$$$NormalPriority$$$HighPriority$$$HighestPriority$$$TimeCriticalPriority$$$InheritPriority -->
<h3 class="fn" id="Priority-enum"><a name="Priority-enum"></a>enum QThread::<span class="name">Priority</span></h3>
<p>This enum type indicates how the operating system should schedule newly created threads.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QThread::IdlePriority</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">scheduled only when no other threads are running.</td></tr>
<tr><td class="topAlign"><code>QThread::LowestPriority</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">scheduled less often than LowPriority.</td></tr>
<tr><td class="topAlign"><code>QThread::LowPriority</code></td><td class="topAlign tblval"><code>2</code></td><td class="topAlign">scheduled less often than NormalPriority.</td></tr>
<tr><td class="topAlign"><code>QThread::NormalPriority</code></td><td class="topAlign tblval"><code>3</code></td><td class="topAlign">the default priority of the operating system.</td></tr>
<tr><td class="topAlign"><code>QThread::HighPriority</code></td><td class="topAlign tblval"><code>4</code></td><td class="topAlign">scheduled more often than NormalPriority.</td></tr>
<tr><td class="topAlign"><code>QThread::HighestPriority</code></td><td class="topAlign tblval"><code>5</code></td><td class="topAlign">scheduled more often than HighPriority.</td></tr>
<tr><td class="topAlign"><code>QThread::TimeCriticalPriority</code></td><td class="topAlign tblval"><code>6</code></td><td class="topAlign">scheduled as often as possible.</td></tr>
<tr><td class="topAlign"><code>QThread::InheritPriority</code></td><td class="topAlign tblval"><code>7</code></td><td class="topAlign">use the same priority as the creating thread. This is the default.</td></tr>
</table></div>
<!-- @@@Priority -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QThread[overload1]$$$QThreadQObject* -->
<h3 class="fn" id="QThread"><a name="QThread"></a>QThread::<span class="name">QThread</span>(<span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a new <a href="qthread.html">QThread</a> to manage a new thread. The <i>parent</i> takes ownership of the <a href="qthread.html">QThread</a>. The thread does not begin executing until <a href="qthread.html#start">start</a>() is called.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>().</p>
<!-- @@@QThread -->
<!-- $$$~QThread[overload1]$$$~QThread -->
<h3 class="fn" id="dtor.QThread"><a name="dtor.QThread"></a><code>[virtual] </code>QThread::<span class="name">~QThread</span>()</h3>
<p>Destroys the <a href="qthread.html">QThread</a>.</p>
<p>Note that deleting a <a href="qthread.html">QThread</a> object will not stop the execution of the thread it manages. Deleting a running <a href="qthread.html">QThread</a> (i.e&#x2e; <a href="qthread.html#isFinished">isFinished</a>() returns <code>false</code>) will result in a program crash. Wait for the <a href="qthread.html#finished">finished</a>() signal before deleting the <a href="qthread.html">QThread</a>.</p>
<!-- @@@~QThread -->
<!-- $$$create[overload1]$$$createFunction&&Args&&... -->
<h3 class="fn" id="create"><a name="create"></a><code>[static] </code><span class="type"><a href="qthread.html#QThread">QThread</a></span> *QThread::<span class="name">create</span>(<span class="type">Function</span> &amp;&amp;<i>f</i>, <span class="type">Args</span> &amp;&amp;... <i>args</i>)</h3>
<p>Creates a new <a href="qthread.html">QThread</a> object that will execute the function <i>f</i> with the arguments <i>args</i>.</p>
<p>The new thread is not started -- it must be started by an explicit call to <a href="qthread.html#start">start</a>(). This allows you to connect to its signals, move QObjects to the thread, choose the new thread's priority and so on. The function <i>f</i> will be called in the new thread.</p>
<p>Returns the newly created <a href="qthread.html">QThread</a> instance.</p>
<p><b>Note: </b>the caller acquires ownership of the returned <a href="qthread.html">QThread</a> instance.</p><p><b>Note: </b>this function is only available when using C++17.</p><p><b>Warning:</b> do not call <a href="qthread.html#start">start</a>() on the returned <a href="qthread.html">QThread</a> instance more than once; doing so will result in undefined behavior.</p>
<p>This function was introduced in  Qt 5.10.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>().</p>
<!-- @@@create -->
<!-- $$$create$$$createFunction&& -->
<h3 class="fn" id="create-1"><a name="create-1"></a><code>[static] </code><span class="type"><a href="qthread.html#QThread">QThread</a></span> *QThread::<span class="name">create</span>(<span class="type">Function</span> &amp;&amp;<i>f</i>)</h3>
<p>Creates a new <a href="qthread.html">QThread</a> object that will execute the function <i>f</i>.</p>
<p>The new thread is not started -- it must be started by an explicit call to <a href="qthread.html#start">start</a>(). This allows you to connect to its signals, move QObjects to the thread, choose the new thread's priority and so on. The function <i>f</i> will be called in the new thread.</p>
<p>Returns the newly created <a href="qthread.html">QThread</a> instance.</p>
<p><b>Note: </b>the caller acquires ownership of the returned <a href="qthread.html">QThread</a> instance.</p><p><b>Warning:</b> do not call <a href="qthread.html#start">start</a>() on the returned <a href="qthread.html">QThread</a> instance more than once; doing so will result in undefined behavior.</p>
<p>This function was introduced in  Qt 5.10.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>().</p>
<!-- @@@create -->
<!-- $$$currentThread[overload1]$$$currentThread -->
<h3 class="fn" id="currentThread"><a name="currentThread"></a><code>[static] </code><span class="type"><a href="qthread.html#QThread">QThread</a></span> *QThread::<span class="name">currentThread</span>()</h3>
<p>Returns a pointer to a <a href="qthread.html">QThread</a> which manages the currently executing thread.</p>
<!-- @@@currentThread -->
<!-- $$$currentThreadId[overload1]$$$currentThreadId -->
<h3 class="fn" id="currentThreadId"><a name="currentThreadId"></a><code>[static] </code><span class="type"><a href="qt.html#HANDLE-typedef">Qt::HANDLE</a></span> QThread::<span class="name">currentThreadId</span>()</h3>
<p>Returns the thread handle of the currently executing thread.</p>
<p><b>Warning:</b> The handle returned by this function is used for internal purposes and should not be used in any application code.</p>
<p><b>Note: </b>On Windows, this function returns the DWORD (Windows-Thread ID) returned by the Win32 function GetCurrentThreadId(), not the pseudo-HANDLE (Windows-Thread HANDLE) returned by the Win32 function GetCurrentThread().</p><!-- @@@currentThreadId -->
<!-- $$$event[overload1]$$$eventQEvent* -->
<h3 class="fn" id="event"><a name="event"></a><code>[override virtual] </code><span class="type">bool</span> QThread::<span class="name">event</span>(<span class="type"><a href="qevent.html">QEvent</a></span> *<i>event</i>)</h3>
<p>Reimplemented from <a href="qobject.html#event">QObject::event</a>().</p>
<!-- @@@event -->
<!-- $$$eventDispatcher[overload1]$$$eventDispatcher -->
<h3 class="fn" id="eventDispatcher"><a name="eventDispatcher"></a><span class="type"><a href="qabstracteventdispatcher.html">QAbstractEventDispatcher</a></span> *QThread::<span class="name">eventDispatcher</span>() const</h3>
<p>Returns a pointer to the event dispatcher object for the thread. If no event dispatcher exists for the thread, this function returns <code>nullptr</code>.</p>
<p>This function was introduced in  Qt 5.0.</p>
<p><b>See also </b><a href="qthread.html#setEventDispatcher">setEventDispatcher</a>().</p>
<!-- @@@eventDispatcher -->
<!-- $$$exec[overload1]$$$exec -->
<h3 class="fn" id="exec"><a name="exec"></a><code>[protected] </code><span class="type">int</span> QThread::<span class="name">exec</span>()</h3>
<p>Enters the event loop and waits until <a href="qthread.html#exit">exit</a>() is called, returning the value that was passed to <a href="qthread.html#exit">exit</a>(). The value returned is 0 if <a href="qthread.html#exit">exit</a>() is called via <a href="qthread.html#quit">quit</a>().</p>
<p>This function is meant to be called from within <a href="qthread.html#run">run</a>(). It is necessary to call this function to start event handling.</p>
<p><b>See also </b><a href="qthread.html#quit">quit</a>() and <a href="qthread.html#exit">exit</a>().</p>
<!-- @@@exec -->
<!-- $$$exit[overload1]$$$exitint -->
<h3 class="fn" id="exit"><a name="exit"></a><span class="type">void</span> QThread::<span class="name">exit</span>(<span class="type">int</span> <i>returnCode</i> = 0)</h3>
<p>Tells the thread's event loop to exit with a return code.</p>
<p>After calling this function, the thread leaves the event loop and returns from the call to <a href="qeventloop.html#exec">QEventLoop::exec</a>(). The <a href="qeventloop.html#exec">QEventLoop::exec</a>() function returns <i>returnCode</i>.</p>
<p>By convention, a <i>returnCode</i> of 0 means success, any non-zero value indicates an error.</p>
<p>Note that unlike the C library function of the same name, this function <i>does</i> return to the caller -- it is event processing that stops.</p>
<p>No QEventLoops will be started anymore in this thread until <a href="qthread.html#exec">QThread::exec</a>() has been called again. If the eventloop in <a href="qthread.html#exec">QThread::exec</a>() is not running then the next call to <a href="qthread.html#exec">QThread::exec</a>() will also return immediately.</p>
<p><b>See also </b><a href="qthread.html#quit">quit</a>() and <a href="qeventloop.html">QEventLoop</a>.</p>
<!-- @@@exit -->
<!-- $$$finished[overload1]$$$finished -->
<h3 class="fn" id="finished"><a name="finished"></a><code>[signal] </code><span class="type">void</span> QThread::<span class="name">finished</span>()</h3>
<p>This signal is emitted from the associated thread right before it finishes executing.</p>
<p>When this signal is emitted, the event loop has already stopped running. No more events will be processed in the thread, except for deferred deletion events. This signal can be connected to <a href="qobject.html#deleteLater">QObject::deleteLater</a>(), to free objects in that thread.</p>
<p><b>Note: </b>If the associated thread was terminated using <a href="qthread.html#terminate">terminate</a>(), it is undefined from which thread this signal is emitted.</p><p><b>Note: </b>This is a private signal. It can be used in signal connections but cannot be emitted by the user.</p>
<p><b>See also </b><a href="qthread.html#started">started</a>().</p>
<!-- @@@finished -->
<!-- $$$idealThreadCount[overload1]$$$idealThreadCount -->
<h3 class="fn" id="idealThreadCount"><a name="idealThreadCount"></a><code>[static] </code><span class="type">int</span> QThread::<span class="name">idealThreadCount</span>()</h3>
<p>Returns the ideal number of threads that can be run on the system. This is done querying the number of processor cores, both real and logical, in the system. This function returns 1 if the number of processor cores could not be detected.</p>
<!-- @@@idealThreadCount -->
<!-- $$$isFinished[overload1]$$$isFinished -->
<h3 class="fn" id="isFinished"><a name="isFinished"></a><span class="type">bool</span> QThread::<span class="name">isFinished</span>() const</h3>
<p>Returns <code>true</code> if the thread is finished; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qthread.html#isRunning">isRunning</a>().</p>
<!-- @@@isFinished -->
<!-- $$$isInterruptionRequested[overload1]$$$isInterruptionRequested -->
<h3 class="fn" id="isInterruptionRequested"><a name="isInterruptionRequested"></a><span class="type">bool</span> QThread::<span class="name">isInterruptionRequested</span>() const</h3>
<p>Return true if the task running on this thread should be stopped. An interruption can be requested by <a href="qthread.html#requestInterruption">requestInterruption</a>().</p>
<p>This function can be used to make long running tasks cleanly interruptible. Never checking or acting on the value returned by this function is safe, however it is advisable do so regularly in long running functions. Take care not to call it too often, to keep the overhead low.</p>
<pre class="cpp">

  <span class="type">void</span> long_task() {
       forever {
          <span class="keyword">if</span> ( <span class="type"><a href="qthread.html#QThread">QThread</a></span><span class="operator">::</span>currentThread()<span class="operator">-</span><span class="operator">&gt;</span>isInterruptionRequested() ) {
              <span class="keyword">return</span>;
          }
      }
  }

</pre>
<p>This function was introduced in  Qt 5.2.</p>
<p><b>See also </b><a href="qthread.html#currentThread">currentThread</a>() and <a href="qthread.html#requestInterruption">requestInterruption</a>().</p>
<!-- @@@isInterruptionRequested -->
<!-- $$$isRunning[overload1]$$$isRunning -->
<h3 class="fn" id="isRunning"><a name="isRunning"></a><span class="type">bool</span> QThread::<span class="name">isRunning</span>() const</h3>
<p>Returns <code>true</code> if the thread is running; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qthread.html#isFinished">isFinished</a>().</p>
<!-- @@@isRunning -->
<!-- $$$loopLevel[overload1]$$$loopLevel -->
<h3 class="fn" id="loopLevel"><a name="loopLevel"></a><span class="type">int</span> QThread::<span class="name">loopLevel</span>() const</h3>
<p>Returns the current event loop level for the thread.</p>
<p><b>Note: </b>This can only be called within the thread itself, i.e&#x2e; when it is the current thread.</p><p>This function was introduced in  Qt 5.5.</p>
<!-- @@@loopLevel -->
<!-- $$$msleep[overload1]$$$msleepunsignedlong -->
<h3 class="fn" id="msleep"><a name="msleep"></a><code>[static] </code><span class="type">void</span> QThread::<span class="name">msleep</span>(<span class="type">unsigned</span> <span class="type">long</span> <i>msecs</i>)</h3>
<p>Forces the current thread to sleep for <i>msecs</i> milliseconds.</p>
<p>Avoid using this function if you need to wait for a given condition to change. Instead, connect a slot to the signal that indicates the change or use an event handler (see <a href="qobject.html#event">QObject::event</a>()).</p>
<p><b>Note: </b>This function does not guarantee accuracy. The application may sleep longer than <i>msecs</i> under heavy load conditions. Some OSes might round <i>msecs</i> up to 10 ms or 15 ms.</p><p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#usleep">usleep</a>().</p>
<!-- @@@msleep -->
<!-- $$$priority[overload1]$$$priority -->
<h3 class="fn" id="priority"><a name="priority"></a><span class="type"><a href="qthread.html#Priority-enum">QThread::Priority</a></span> QThread::<span class="name">priority</span>() const</h3>
<p>Returns the priority for a running thread. If the thread is not running, this function returns <code>InheritPriority</code>.</p>
<p>This function was introduced in  Qt 4.1.</p>
<p><b>See also </b><a href="qthread.html#Priority-enum">Priority</a>, <a href="qthread.html#setPriority">setPriority</a>(), and <a href="qthread.html#start">start</a>().</p>
<!-- @@@priority -->
<!-- $$$quit[overload1]$$$quit -->
<h3 class="fn" id="quit"><a name="quit"></a><code>[slot] </code><span class="type">void</span> QThread::<span class="name">quit</span>()</h3>
<p>Tells the thread's event loop to exit with return code 0 (success). Equivalent to calling <a href="qthread.html#exit">QThread::exit</a>(0).</p>
<p>This function does nothing if the thread does not have an event loop.</p>
<p><b>See also </b><a href="qthread.html#exit">exit</a>() and <a href="qeventloop.html">QEventLoop</a>.</p>
<!-- @@@quit -->
<!-- $$$requestInterruption[overload1]$$$requestInterruption -->
<h3 class="fn" id="requestInterruption"><a name="requestInterruption"></a><span class="type">void</span> QThread::<span class="name">requestInterruption</span>()</h3>
<p>Request the interruption of the thread. That request is advisory and it is up to code running on the thread to decide if and how it should act upon such request. This function does not stop any event loop running on the thread and does not terminate it in any way.</p>
<p>This function was introduced in  Qt 5.2.</p>
<p><b>See also </b><a href="qthread.html#isInterruptionRequested">isInterruptionRequested</a>().</p>
<!-- @@@requestInterruption -->
<!-- $$$run[overload1]$$$run -->
<h3 class="fn" id="run"><a name="run"></a><code>[virtual protected] </code><span class="type">void</span> QThread::<span class="name">run</span>()</h3>
<p>The starting point for the thread. After calling <a href="qthread.html#start">start</a>(), the newly created thread calls this function. The default implementation simply calls <a href="qthread.html#exec">exec</a>().</p>
<p>You can reimplement this function to facilitate advanced thread management. Returning from this method will end the execution of the thread.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>() and <a href="qthread.html#wait">wait</a>().</p>
<!-- @@@run -->
<!-- $$$setEventDispatcher[overload1]$$$setEventDispatcherQAbstractEventDispatcher* -->
<h3 class="fn" id="setEventDispatcher"><a name="setEventDispatcher"></a><span class="type">void</span> QThread::<span class="name">setEventDispatcher</span>(<span class="type"><a href="qabstracteventdispatcher.html">QAbstractEventDispatcher</a></span> *<i>eventDispatcher</i>)</h3>
<p>Sets the event dispatcher for the thread to <i>eventDispatcher</i>. This is only possible as long as there is no event dispatcher installed for the thread yet. That is, before the thread has been started with <a href="qthread.html#start">start</a>() or, in case of the main thread, before <a href="qcoreapplication.html">QCoreApplication</a> has been instantiated. This method takes ownership of the object.</p>
<p>This function was introduced in  Qt 5.0.</p>
<p><b>See also </b><a href="qthread.html#eventDispatcher">eventDispatcher</a>().</p>
<!-- @@@setEventDispatcher -->
<!-- $$$setPriority[overload1]$$$setPriorityQThread::Priority -->
<h3 class="fn" id="setPriority"><a name="setPriority"></a><span class="type">void</span> QThread::<span class="name">setPriority</span>(<span class="type"><a href="qthread.html#Priority-enum">QThread::Priority</a></span> <i>priority</i>)</h3>
<p>This function sets the <i>priority</i> for a running thread. If the thread is not running, this function does nothing and returns immediately. Use <a href="qthread.html#start">start</a>() to start a thread with a specific priority.</p>
<p>The <i>priority</i> argument can be any value in the <code>QThread::Priority</code> enum except for <code>InheritPriorty</code>.</p>
<p>The effect of the <i>priority</i> parameter is dependent on the operating system's scheduling policy. In particular, the <i>priority</i> will be ignored on systems that do not support thread priorities (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details).</p>
<p>This function was introduced in  Qt 4.1.</p>
<p><b>See also </b><a href="qthread.html#Priority-enum">Priority</a>, <a href="qthread.html#priority">priority</a>(), and <a href="qthread.html#start">start</a>().</p>
<!-- @@@setPriority -->
<!-- $$$setStackSize[overload1]$$$setStackSizeuint -->
<h3 class="fn" id="setStackSize"><a name="setStackSize"></a><span class="type">void</span> QThread::<span class="name">setStackSize</span>(<span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> <i>stackSize</i>)</h3>
<p>Sets the maximum stack size for the thread to <i>stackSize</i>. If <i>stackSize</i> is greater than zero, the maximum stack size is set to <i>stackSize</i> bytes, otherwise the maximum stack size is automatically determined by the operating system.</p>
<p><b>Warning:</b> Most operating systems place minimum and maximum limits on thread stack sizes. The thread will fail to start if the stack size is outside these limits.</p>
<p><b>See also </b><a href="qthread.html#stackSize">stackSize</a>().</p>
<!-- @@@setStackSize -->
<!-- $$$setTerminationEnabled[overload1]$$$setTerminationEnabledbool -->
<h3 class="fn" id="setTerminationEnabled"><a name="setTerminationEnabled"></a><code>[static protected] </code><span class="type">void</span> QThread::<span class="name">setTerminationEnabled</span>(<span class="type">bool</span> <i>enabled</i> = true)</h3>
<p>Enables or disables termination of the current thread based on the <i>enabled</i> parameter. The thread must have been started by <a href="qthread.html">QThread</a>.</p>
<p>When <i>enabled</i> is false, termination is disabled. Future calls to <a href="qthread.html#terminate">QThread::terminate</a>() will return immediately without effect. Instead, the termination is deferred until termination is enabled.</p>
<p>When <i>enabled</i> is true, termination is enabled. Future calls to <a href="qthread.html#terminate">QThread::terminate</a>() will terminate the thread normally. If termination has been deferred (i.e&#x2e; <a href="qthread.html#terminate">QThread::terminate</a>() was called with termination disabled), this function will terminate the calling thread <i>immediately</i>. Note that this function will not return in this case.</p>
<p><b>See also </b><a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@setTerminationEnabled -->
<!-- $$$sleep[overload1]$$$sleepunsignedlong -->
<h3 class="fn" id="sleep"><a name="sleep"></a><code>[static] </code><span class="type">void</span> QThread::<span class="name">sleep</span>(<span class="type">unsigned</span> <span class="type">long</span> <i>secs</i>)</h3>
<p>Forces the current thread to sleep for <i>secs</i> seconds.</p>
<p>Avoid using this function if you need to wait for a given condition to change. Instead, connect a slot to the signal that indicates the change or use an event handler (see <a href="qobject.html#event">QObject::event</a>()).</p>
<p><b>Note: </b>This function does not guarantee accuracy. The application may sleep longer than <i>secs</i> under heavy load conditions.</p><p><b>See also </b><a href="qthread.html#msleep">msleep</a>() and <a href="qthread.html#usleep">usleep</a>().</p>
<!-- @@@sleep -->
<!-- $$$stackSize[overload1]$$$stackSize -->
<h3 class="fn" id="stackSize"><a name="stackSize"></a><span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> QThread::<span class="name">stackSize</span>() const</h3>
<p>Returns the maximum stack size for the thread (if set with <a href="qthread.html#setStackSize">setStackSize</a>()); otherwise returns zero.</p>
<p><b>See also </b><a href="qthread.html#setStackSize">setStackSize</a>().</p>
<!-- @@@stackSize -->
<!-- $$$start[overload1]$$$startQThread::Priority -->
<h3 class="fn" id="start"><a name="start"></a><code>[slot] </code><span class="type">void</span> QThread::<span class="name">start</span>(<span class="type"><a href="qthread.html#Priority-enum">QThread::Priority</a></span> <i>priority</i> = InheritPriority)</h3>
<p>Begins execution of the thread by calling <a href="qthread.html#run">run</a>(). The operating system will schedule the thread according to the <i>priority</i> parameter. If the thread is already running, this function does nothing.</p>
<p>The effect of the <i>priority</i> parameter is dependent on the operating system's scheduling policy. In particular, the <i>priority</i> will be ignored on systems that do not support thread priorities (such as on Linux, see the <a href="http://linux.die.net/man/2/sched_setscheduler">sched_setscheduler</a> documentation for more details).</p>
<p><b>See also </b><a href="qthread.html#run">run</a>() and <a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@start -->
<!-- $$$started[overload1]$$$started -->
<h3 class="fn" id="started"><a name="started"></a><code>[signal] </code><span class="type">void</span> QThread::<span class="name">started</span>()</h3>
<p>This signal is emitted from the associated thread when it starts executing, before the <a href="qthread.html#run">run</a>() function is called.</p>
<p><b>Note: </b>This is a private signal. It can be used in signal connections but cannot be emitted by the user.</p>
<p><b>See also </b><a href="qthread.html#finished">finished</a>().</p>
<!-- @@@started -->
<!-- $$$terminate[overload1]$$$terminate -->
<h3 class="fn" id="terminate"><a name="terminate"></a><code>[slot] </code><span class="type">void</span> QThread::<span class="name">terminate</span>()</h3>
<p>Terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating system's scheduling policies. Use <a href="qthread.html#wait">QThread::wait</a>() after terminate(), to be sure.</p>
<p>When the thread is terminated, all threads waiting for the thread to finish will be woken up.</p>
<p><b>Warning:</b> This function is dangerous and its use is discouraged. The thread can be terminated at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to clean up after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.</p>
<p>Termination can be explicitly enabled or disabled by calling <a href="qthread.html#setTerminationEnabled">QThread::setTerminationEnabled</a>(). Calling this function while termination is disabled results in the termination being deferred, until termination is re-enabled. See the documentation of <a href="qthread.html#setTerminationEnabled">QThread::setTerminationEnabled</a>() for more information.</p>
<p><b>See also </b><a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a>().</p>
<!-- @@@terminate -->
<!-- $$$usleep[overload1]$$$usleepunsignedlong -->
<h3 class="fn" id="usleep"><a name="usleep"></a><code>[static] </code><span class="type">void</span> QThread::<span class="name">usleep</span>(<span class="type">unsigned</span> <span class="type">long</span> <i>usecs</i>)</h3>
<p>Forces the current thread to sleep for <i>usecs</i> microseconds.</p>
<p>Avoid using this function if you need to wait for a given condition to change. Instead, connect a slot to the signal that indicates the change or use an event handler (see <a href="qobject.html#event">QObject::event</a>()).</p>
<p><b>Note: </b>This function does not guarantee accuracy. The application may sleep longer than <i>usecs</i> under heavy load conditions. Some OSes might round <i>usecs</i> up to 10 ms or 15 ms; on Windows, it will be rounded up to a multiple of 1 ms.</p><p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#msleep">msleep</a>().</p>
<!-- @@@usleep -->
<!-- $$$wait[overload1]$$$waitunsignedlong -->
<h3 class="fn" id="wait"><a name="wait"></a><span class="type">bool</span> QThread::<span class="name">wait</span>(<span class="type">unsigned</span> <span class="type">long</span> <i>time</i> = ULONG_MAX)</h3>
<p>Blocks the thread until either of these conditions is met:</p>
<ul>
<li>The thread associated with this <a href="qthread.html">QThread</a> object has finished execution (i.e&#x2e; when it returns from <a href="qthread.html#run">run</a>()). This function will return true if the thread has finished. It also returns true if the thread has not been started yet.</li>
<li><i>time</i> milliseconds has elapsed. If <i>time</i> is ULONG_MAX (the default), then the wait will never timeout (the thread must return from <a href="qthread.html#run">run</a>()). This function will return false if the wait timed out.</li>
</ul>
<p>This provides similar functionality to the POSIX <code>pthread_join()</code> function.</p>
<p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@wait -->
<!-- $$$yieldCurrentThread[overload1]$$$yieldCurrentThread -->
<h3 class="fn" id="yieldCurrentThread"><a name="yieldCurrentThread"></a><code>[static] </code><span class="type">void</span> QThread::<span class="name">yieldCurrentThread</span>()</h3>
<p>Yields execution of the current thread to another runnable thread, if any. Note that the operating system decides to which thread to switch.</p>
<!-- @@@yieldCurrentThread -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>