<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[how do we check the object&#x27;s thread on which it is living]]></title><description><![CDATA[<p dir="auto">for instance i have a QObject pointer created one of the thread in my application and consumed in another thread.<br />
I wanted to know which thread owns that object.<br />
is there any API for that?<br />
QObject::thread()::currentThreadId() - is returning calling thread id(from where we  are invoking ) only.</p>
<p dir="auto">eg:<br />
Thread 1<br />
{<br />
QObject* object = new QObject();<br />
}<br />
Thread 2<br />
{<br />
/// Below line is not the one i want<br />
object-&gt;thread()-&gt;currentThreadId(); /// <strong>Returns Thread 2's id only</strong><br />
<strong>/// I want a solution something like below line</strong><br />
object-&gt;thread()-&gt;threadId() /// <strong>Returns Thread 1's id.</strong><br />
}<br />
Anyone plz help me.</p>
<p dir="auto">Thanks in advance,<br />
Raj</p>
]]></description><link>https://forum.qt.io/topic/117302/how-do-we-check-the-object-s-thread-on-which-it-is-living</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 12:49:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/117302.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Jul 2020 05:45:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how do we check the object&#x27;s thread on which it is living on Sat, 25 Jul 2020 06:08:18 GMT]]></title><description><![CDATA[<p dir="auto">Ok. understood. I will compare QThread* instead of thread id.</p>
<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/bonnie">@<bdi>Bonnie</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>  for your help.</p>
]]></description><link>https://forum.qt.io/post/608680</link><guid isPermaLink="true">https://forum.qt.io/post/608680</guid><dc:creator><![CDATA[RAJEESHR]]></dc:creator><pubDate>Sat, 25 Jul 2020 06:08:18 GMT</pubDate></item><item><title><![CDATA[Reply to how do we check the object&#x27;s thread on which it is living on Fri, 24 Jul 2020 06:30:33 GMT]]></title><description><![CDATA[<p dir="auto"><code>currentThreadId()</code> is a static funtion. It has nothing to do with the object or its living thread...<br />
<code>object-&gt;thread()-&gt;currentThreadId()</code> equals <code>QThread::currentThreadId()</code>.<br />
Also the doc says:</p>
<blockquote>
<p dir="auto">Warning: The handle returned by this function is used for internal purposes and should not be used in any application code.</p>
</blockquote>
<p dir="auto">So better not to use this function.</p>
<p dir="auto">For "which thread owns that object", you already write that, it is just <code>object-&gt;thread()</code>.<br />
Don't know why you must get a thread id...But QThread seems not providing an API for that.<br />
If you want to compare, just compare the pointer address.</p>
]]></description><link>https://forum.qt.io/post/608524</link><guid isPermaLink="true">https://forum.qt.io/post/608524</guid><dc:creator><![CDATA[Bonnie]]></dc:creator><pubDate>Fri, 24 Jul 2020 06:30:33 GMT</pubDate></item><item><title><![CDATA[Reply to how do we check the object&#x27;s thread on which it is living on Fri, 24 Jul 2020 06:00:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rajeeshr">@<bdi>RAJEESHR</bdi></a> said in <a href="/post/608520">how do we check the object's thread on which it is living</a>:</p>
<blockquote>
<p dir="auto">I wanted to know which thread owns that object.</p>
</blockquote>
<p dir="auto">Either the thread where the object was created or the thread to which the object was moved using <a href="https://doc.qt.io/qt-5/qobject.html#moveToThread" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qobject.html#moveToThread</a></p>
<p dir="auto">To find out in which thread an object lives use <a href="https://doc.qt.io/qt-5/qobject.html#thread" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qobject.html#thread</a></p>
]]></description><link>https://forum.qt.io/post/608522</link><guid isPermaLink="true">https://forum.qt.io/post/608522</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 24 Jul 2020 06:00:08 GMT</pubDate></item></channel></rss>