I have a threadSafe method that gets called by multiple threads. Is there a way to know which thread called it?
+1
A:
If you need it, you could add a threadId
parameter, and let it thread pass it to the method
Samuel Carrijo
2010-02-25 17:52:04
yeah I was aware of that but I wanted to minimize user intervention so as to not let anyone call the function in the wrong way, now user has to know if its a mainthread or qthread call. So it would have to add that parameter only when working in the qthread
yan bellavance
2010-02-25 22:18:40
+3
A:
Well, you know the thread that calls the method, and by extension the same thread will be active inside that method call. You can just call QThread::currentThread()
to get this.
Chris Dennett
2010-02-25 23:20:43
actually there is no method called getCurrentThread but the there is a static in QThread called currentThread...ill try it.
yan bellavance
2010-02-26 00:41:33
Ah yes, sorry -- I thought the original post said Java :) I got currentThread wrong in Java too, it is in fact Thread.currentThread() here too, ugh :) Anyway, glad my post helped; looks like the two APIs have similarly named classes / methods anyway :)
Chris Dennett
2010-02-26 00:58:44